Names of other planets and stars are proper nouns, and should be capitalized. For example, "The planet Mars can be seen tonight in the constellation Gemini, near the star Pollux".
The words sun, earth, and moon are to be capitalized when being used in an astronomical context as proper nouns. Hence, "The Sun is a main sequence star, with a spectral class of G2." However, in a non-scientific context, do not capitalize. So, "It was a lovely day and the sun was warm." Also, take care that these words are only capitalized when referring to the name of a specific body. "The Moon orbits the Earth" refers to the names of two bodies. However, "Pluto's moon Charon" uses moon as a conventional noun.