The sun is the heat source that makes the Earth habitable. Solar radiation warms the surface of the planet during the day, and the surface radiates that heat back out at night. The Earth's atmosphere traps much of this radiated energy, reflecting it back down to keep the planet at a habitable temperature day and night.
Atmospheres make an enormous difference in how much of the sun's heat a planet can retain. On the moon, which has no atmosphere, temperatures can reach 250 degrees Fahrenheit in the sunlight and -250 degrees Fahrenheit in the shade. This extreme temperature swing is why NASA had to develop protective shielding for their spacecraft and insulated spacesuits for astronauts in order to survive in space. Without the atmosphere, the Earth's temperature would reach similar extremes, rendering it uninhabitable.
Too heavy an atmosphere can also be a problem. Venus is closer to the sun and has an atmosphere about 93 times as dense as Earth's. This allows the planet to trap much more of the sun's heat, raising its average temperature to 864 degrees Fahrenheit. This is actually a warmer average temperature than that found on planet Mercury, which reaches 788 degrees Fahrenheit during the day and falls to -364 degrees Fahrenheit at night.