phew, those are quite hard questions.
The photon comes out of nowhere, since it is massless, no matter is created.
But in fact, sometimes even matter comes out of nowhere (called Energy-Time uncertainty I think), that is quite an interesting topic. But nevermind.
I do not feel like I can appropriately explain the process of creating a photon with energy, to be honest. If noone else can, I might do some research, this sounds interesting.