As you know, it gets hot outside if the sun is shining brightly on a summer day. The reason it warms up is because the earth is absorbing some of that solar energy. However, not all of the energy is absorbed. Some energy is reflected back into space in the form of light. This reflection allows the earth to be seen as a star from other parts of our solar system, just like we can see the moon and other planets.
Energy also leaves the earth in other forms like heat, for example, which is called infrared light.
If we have more energy leaving than arriving, the earth will cool down and we could have another ice age. If we have more energy arriving than leaving, we will have global warming. The reason the earth could retain more energy than it gives off has to do with the air around us and what it is made of. Carbon dioxide is a gas that can't be seen or smelled, but it does trap some of the infrared energy emitted from the Earth and prevents that energy from going back out into space. If the amount of CO2 in the air goes up, the earth will heat up, which is the start of global warming.