First and foremost invest in a tripod. A firm surface isn't always going to be available plus its not always going to be exactly where you want to compose your picture - and there's no guarantee it will be level.
Second, your camera has a maximum shutter speed of 30 seconds and a self-timer. Use the self-timer to release the shutter.
I use and recommend this site for low-light exposures:
http://www.calculator.org/exposure.aspx
I used the Scene 'Distant view of city skyline or floodlit buildings' and ISO 200 for these pictures:
http://www.flickr.com/photos/drifter45h/4048051455/ 100mm @ f11, exposure of 30 seconds.
http://www.flickr.com/photos/drifter45h/4048796836/ 200mm @ f11, exposure of 30 seconds.
When photographing the moon, if you use ISO 100, try an exposure of f16 at 1/100 sec. If you aren't happy with the results try f11 @ 1/100 sec.
Unless you plan on investing in an equatorial mount for your tripod about all you can do when photographing stars is create star trails. This site explains this:
http://www.danheller.com/star-trails
Here are a couple of sites that seal with astrophotography:
http://astropix.com
http://www.popphoto.com/how-to/2008/12/how-to-astrophotography-101
For sunsets put your camera in Aperture Priority and use a small f-stop such as f11 or f16. Use your tripod.
This video tutorial will help you learn more about your camera:
http://www.nikondigitutor.com/eng/d5000/index.shtml Who better than Nikon to teach you all about your Nikon D5000?
So read everything referenced, buy a tripod, and enjoy night photography.