Heat transfers by three methods, conduction, convection, and radiation. In conduction two solids need to be in direct contact one hotter than the other in order for the heat to transfer like when you place your hand on the wall in a hot summer. In convection a solid and a liquid, or a solid and a gas will have to be in contact in order for the transfer to take place, like the water in a hot pan.
While the previous two methods require a material medium (solid, liquid, gas) in order for heat to transfer, Radiation does not.
Every material body emits heat radiation. The wall in the hot summer, for instance emits heat radiation, and that heat radiation affects the temperature of the room. The fact of the matter is that this wall will continue to emit radiation even if there's no air in this room, yet it will be much cooler, why, read on..
Another fact you should know, is when an object becomes really hot it starts to emit heat in the form of light. The simplest example is fire.
You might've noticed when you place your hand in direct sun light it gets warmer. So in order for this light to transform to heat it needs to fall on a material object, your hand, the air in the atmosphere (which makes the temperature here on earth much warmer than in space, or your filled with air room), or water in the seas, etc..
The atmosphere thus gets hotter by day time, and loses some of that heat by night, mostly radiate it to outer space, because the light from the sun is absent to make up for the loss.
In space you don't have the atmosphere, so either the sun is there to give light or it's not. That's why it's very cold when the light from the sun is absent.
When the sun light is there, it's relatively hot because there's no atmosphere to shield you from the majority of the sun's rays, as the case at ground level on earth. That's one of the reasons why astronauts wear these thick suits when they go out there.
That's the simplest as it gets regarding answering your questions, so I hope that helps.