Fire works by taking burnable molecules, normally made mostly out of carbon, hydrogen, and oxygen (the oxygen does not "burn," but is a part of paper and firewood, for example). There also cases in which other elements burn, like nitrogen and metals. When these things burn, oxygen from the air will oxidize the other atoms to their oxide form. For example, carbon burns to carbon dioxide, hydrogen burns to water, etc. This process releases a LOT of energy! Some of this energy ends up as light; you can see it as a blue flame if you are burning wood or gas.
However, most of the energy ends up as heat. Yellow flames are bits of unburned carbon which are being heated to thousands of degrees, causing them to glow the same reason a light bulb does. Once the yellow flame cools, it becomes smoke and soot. This is why burning a lot of candles inside will make the walls dirty; the yellow candle flame is polluting a lot like how coal is polluting.
So the bottom line is, the chemical reaction happening in fire releases a lot of energy, which ends up as heat and light.