Within the star (our sun) fusion reactions take place in it's core to generate radiation. To go into this properly you need to know about nuclear fusion but basically the binding energy released when helium is produced in the sun is transformed (mostly) to photon energy (radiation).
It is the energy of this radiation that the earth is receiving.
There is much more to it than this and I don't want to give an over complicated answer.
@PM 2Ring has given you a good explanation of where the energy goes in the comment below. I will just expand a little on a point made in that comment since you are asking 'where does the energy go after leaving earth?'
Basically, this process of 'absorption and re-emission' of the radiation (described in the comment) will continue with other bodies in space after the radiation has left the earth.
So you may be wondering at this point; Where does the energy all go in the end? I don't have a good answer to this and I don't know if such an answer even exists.
However, I can tell you that most energy is transformed to heat (energy) eventually.