The Sun gives out radiation, mostly visible light and ultraviolet radiation, which has a short wavelength. Most of this passes through the atmosphere and is absorbed by the Earth's surface, which warms up.
The warm surface then radiates energy back out as infrared radiation, which has a longer wavelength. Some gases in the atmosphere absorb this infrared radiation. These are the greenhouse gases, and they include carbon dioxide, methane and water vapour.
The greenhouse gases do not keep the energy. They re-radiate it in all directions, and some of it goes back towards the Earth's surface. This keeps the surface warmer than it would be without an atmosphere. Without this natural greenhouse effect the Earth would be too cold for most life.
The problem is not the greenhouse effect itself but an increase in it. More greenhouse gas in the air means more infrared radiation is absorbed and re-radiated back, so the average temperature rises. This is what we call global warming. The ozone hole is a different problem and is not the cause of the greenhouse effect.