Blackbodies emit most of their radiation at shorter wavelengths when they get hotter. The sun is much hotter than the Earth, and given that they are near-blackbodies, the sun will emit most of its radiation at short wavelengths (visible light) while the Earth emits most of its radiation in longer wavelengths (IR).

The atmosphere, however, is not a blackbody. The absorption spectrum in the bottom diagram (% of radiation absorbed) shows holes, whereas a blackbody should have 100% absorption all the way across. Note that the holes, where most of the radiation is transmitted, occurs in the visible spectrum (good for us, because it lets the sunlight through to the ground) and around the peak of the Earth IR (also good, because if it was all absorbed, the atmosphere and Earth might get too hot, as it has on Venus). This second hole in the absorption spectrum, in the IR region, is called the Atmospheric Window, given that windows transmit radiation. A considerable amount of IR in the wavelengths just outside this window is still being absorbed by the atmosphere, so the atmosphere is going to be warmed.

 

The atmospheric greenhouse effect is going to depend on the fact that the sun and Earth are blackbodies, and the atmosphere is transparent to visible light but partially opaque to IR. When the atmosphere absorbs IR, it must also radiate it to be in radiative equilibrium. The IR the atmosphere radiates toward the Earth is absorbed by the blackbody Earth, along with the sunlight that got transmitted through the atmosphere. The Earth is now receiving more energy than it would if there were not atmosphere (it would just be the sunlight in that case), so it must radiate more to compensate, if it is to remain in radiative equilibrium. The higher the amount of radiation emitted, the higher the temperature of the object. This effective warming of the lower atmosphere by the "recirculation" of energy in the form of IR radiation is the greenhouse effect.

See a Shockwave movie of the greenhouse effect