A flame is the result of a chemical reaction between a fuel and the oxygen in the air. As a result of this reaction, the fuel - which can be solid (e.g., candle) or liquid (e.g., oil) turns into hot gas, which emits light. If you look closely at a flame, you will see that it has several colours. The bottom is typically blue, while above it there are red, orange and most of it is yellow. Needless to say, the flame is hot!
If you consider the most popular candles, they are made from paraffin wax. Chemically, the paraffin wax is made from two types of atoms: carbon and hydrogen which are bounded tightly together (its chemical composition is C25H52, namely 25 atoms of carbon are attached to 52 atoms of hydrogen). In fact, many materials that can serve as fuel, are made of these atoms, namely carbon and hydrogen which are bound tightly together. In order to get a flame, one needs oxygen. Oxygen is very ubiquitous in the earth's atmosphere- about 21% of the air is made of oxygen, which is needed for us to breath.
When oxygen come in contact with the fuel under regular conditions, nothing much happens. However, when enough heat is added, the chemical bonds between the carbon and the hydrogen can break; this is known as pyrolysis. At this stage, the fuel changes its properties irreversibly, and turns into a gas (still of carbon and hydrogen, but now with different chemical composition).
At a second stage, the small gaseous molecules of hydrogen and carbon interact with the oxygen in the air. This changes again the chemical composition of the gas molecules, typically producing molecules such as CO2 and H2O. The carbon and hydrogen are now chemically bonded with the oxygen. During this process, a large amount of energy is released, and atoms are excited; as a result, they emit light, in a process known as chemiluminescence. This causes the emission of a blue light from the hot gas, seen as a blue flame.
Since this chemical reaction between the fuel molecules and the oxygen in the air (known as oxidation) releases energy, this gas is very hot.
When there are leftover carbon molecules that do not interact with the oxygen, they are bound together, forming a soot. These molecules are very large (relative to the atoms). As they absorb heat, they start glowing - emitting light, in a process known as incandescence (light emission as a result of heat). This emission produces the different colours we see: red, orange and yellow.
So, the flames we see are really the result of emission of light from hot gases produced by chemical reaction between the fuel and oxygen in the air. Since hot gases are less dense then cold ones, these gases tend to rise up, producing the typical flame shape we are used to. Being hot gases also explains why the flames change their shape continuously, and in particular when wind is present.
A nice movie explaining this can be found at: