Energy from the sun reaches Earth by way of radiation. Heat can be transferred in three ways: conduction, convection and radiation. Radiation is the only way to transfer heat through empty space.
The sun cannot conduct heat to the Earth directly because the two bodies are not in contact with each other. Convection is also impossible, as no medium connects the two bodies to facilitate heat flow. Instead, the sun radiates much of its energy as light of various wavelengths. Some of this radiated light is in the infrared part of the spectrum and reaches Earth as heat.
Light in the visible part of the spectrum also has the effect of warming the Earth. It does this by penetrating the atmosphere and being absorbed by the land and water. Once the Earth has absorbed all of the energy it can hold, it begins to radiate energy back toward space. This terrestrial radiation is primarily in the infrared band of the spectrum, which is absorbed by aerosols in the atmosphere. These greenhouse gases trap heat and store up the surplus energy of the Earth's allotment of solar radiation. Eventually, even the atmosphere reaches thermal saturation and radiates waste energy back out into space.