right what condition are you shooting at? Shutter speed will not give you a condition, because if say you have set for 1/60s and it's a pitch dark room then even with the fastest aperture know to man f1.2 you won't get much on a shot with ISO6400 even.
And with manual you have no chance.
Aperture Priority - set the aperture and computer will calculate the require shutter speed. This is the best as shutter speeds can vary from 1/2000s to 30s which gives you a massive range of exposure.
Shutter Priority - set the shutter speed and computer will calculate the required aperture size. This is limited to the largest possible aperture size you have on your lens. This is not very versitle and thus give you the message that the exposure is too dark.
Manual - you choose, well if you know what you are doing then fine. Else, avoid.
So under the dark conditions, use aperture always. (I always use aperture, unless its sports, or motion stop pictures or compiling HDRs or nightshots or similar temperal based shots)
you question isn't with regard to D40 specifically, but understanding how each mode works in all camera's. I hope this info helps you a bit.