seems to have been answered already but here's my input: we, in the english language, happen to have named our sun after the word for sun. so, when it is important to emphasise you are referring to *our sun*, capitalise it as The Sun. when it doesn't really matter, just say the sun.
and the same goea for celestial bodies like the Moon and the Earth. Moon and Earth are *names* as well as words. So, when using it as a name, capitalise them, like the basic rule says