The Earth is continuously receiving energy from the sun. Energy also leaves the Earth in the nighttime (of course in the form of invisible infrared energy!). Otherwise, the Earth would be continuously warming up. This delicate balance between the energy coming in and leaving due to natural greenhouse effect is what keeps the planet warm enough for us to live on.
It is very obvious that if more energy comes in than the energy that leaves, the planet will become warm. Similarly, if the energy that leaves is more than the energy that comes in, the planet will become cool. The atmospheric temperature fluctuates over centuries due to certain natural causes.
Go to the next screen to view an animation of the greenhouse effect.