Purpose of the candles
Quick history lesson: The Jewish people were suffering in the land of Israel back in 168 BC under the Syrian Greek King Antiochus. He made life difficult for them. He issued a series of decrees forbidding circumcision, the keeping of Shabbat, and the study of Torah. One day his people set up statues/ idols of Zeus throughout the land of Israel and made the people, including the Jews, bow down to them. He even went so far as to sacrifice a pig in the Jewish Temple in Jerusalem. Not good for public relations with Jewish people. (Jews don't eat pig products and spilling wrong blood in the sacred place would have desecrated the place.)
A Jewish family named the Maccabees rose up and withstood the status quo, raised a small militia to fight against Antiochus and after three years pushed them out of the Temple area. The revolutionaries dedicated the Temple back to the Lord God and that's the end of the story. The Hebrew word for 'dedicate' is "Hanukkah" so the holiday (Dedication) is a reminder every year that sometimes the little guy can beat up the bad guy (Compare David and Goliath) and God can win victories for His people who trust Him.
Then the questions arise about candles and 7 or 8 or 9 of them at that.
According to the legend, the priests found a bit of oil, only enough to light the menorah (7-branched candelabrum) for one day, but after 8 days the lights still flickered. By then the priests were able to consecrate new oil and normalcy returned to the Temple. So since the oil lasted for 8 days, we celebrate the holiday for 8 days. Also since oil was so 'central' to the holiday then, we eat foods fried in oil like potato pancakes (latkes) and doughnuts (sufganiyot).
So why 9 candles or 7 or 8?
The eight days of the 'miracle' are noted by lighting 8 candles. The bonus candle is titled the 'shamash' or servant candle. The candles are normally allowed to burn out on their own after a minimum of 1/2 hour, but if necessary they can be blown out at any time after that 1/2 hour.
Why the shamash candle? The Hanukkah candles are for pleasure only; we are not allowed to use them for any productive purpose. We keep an extra one around (the shammus), so that if we need to do something useful with a candle, we don't accidentally use the Hanukkah candles. The extra candle is at a different height so that it is easily identified as the shamash.
Hope that helps!