The phenomenon you're referring to is black body radiation. When a material gets hot, its electrons are in excited states. Occasionally, an electron will drop down to a lower state, emitting a photon. The higher the temperature, the higher the frequency of emitted light.
This is why the heating element in your oven turns red. It's also how incandescent light bulbs work. Most of the light we see from stars is due to black body radiation, and we can infer the temperature of a star by its color because of this.
The equation that gives energy emitted as a function of frequency and temperature is Plank's Law.