The bottom line is that there is little consensus in all usage cases, but guidelines exist.
Typically, we capitalize the names of astronomical bodies, except when there's a preceding article ("Earth" or "the earth"). Earth is never capitalized when referring to soil or land—only when referring to the planet as a whole.
NASA and ESA (among others) prefer to capitalize Moon when referring to Earth's moon as a special case. My guess is that nobody says "Moon is out tonight!", as they would with Jupiter or Venus. We always add "the" to the Moon. It's as if we give it special consideration because doesn't have its own, standalone name. (Some may disagree on this point, preferring to always refer to it always as "the moon", following the rule mentioned above.)
- Correct: "The sun is far from the earth."
- Correct: "The sun is far from Earth."
- Correct: "Jupiter has several moons."
- Correct: "The Moon is right next to the horizon."
- Incorrect: "The Earth is far from the Sun."
- Incorrect: "The Sun gives light to our moon."
- Incorrect (debatable): "The moon is bright tonight."
There are a number of excellent examples on the MLA page here:
Note also that the name of our host star, the sun, is "Sol". We can say "Sol is larger than Earth", or "The Sun is larger than Earth" or "The sun is out today", but we would say "Sol is larger than Earth" rather than "Sun is larger than Earth".