The amount of energy leaving the planet is nearly identical to the amount of solar energy being received. (Radioactive decay in the interior of the Earth makes the outgoing number slightly larger.)
Without greenhouse gases, the surface heat would immediately radiate back into space, and the atmosphere would be very cold. Greenhouse gases impede the return of energy to space. In other words they act as an insulator. They absorb photons of certain wavelengths, excite the molecules, and heat them. Many of these excited molecules then pass the heat on to neighboring molecules.
Because of these insulators known as greenhouse gases restricting the energy flow, in order to maintain energy equilibrium, the temperature has to rise near the surface – because heat flow is proportional to the difference in temperature. Increased temperature near the surface causes increased LW radiation, increased conduction, and increased convection – all needed to maintain equilibrium.
It is called conservation of energy.