The thing that makes a firefly a firefly is one of its most unique and important adaptations... Bioluminescence!!

One of the major uses of bioluminescence, for the firefly, is for a male to attract a female during a fairly complex mating ritual. You can learn more about these rituals on the reproduction page.

Along with being a part of the mating ritual, it is not uncommon for these flash signals to be used as a trap. Very often the female of one species of firefly (Photnius pyralis) will mimic the light pattern of another species to attract a male of the opposite species. Once the female has a found a male of the opposite species, she lays a trap for him to come to here. Once they are united the female will eat the male and use his defense chemicals to protect her eggs. This not only reduces other species competition, but it also helps ensure her offspring's survival. 

One more adaptation of the firefly is its use of a foul-tasting chemical, called a lucibufagins, that they produce. The use of this chemical, which acts as a steroid, causes any predator that were to eat the firefly to vomit almost immediately after ingestion. This will cause that predator to avoid other fireflies in the future. This is the same chemical that the female in the previous section uses to protect her eggs.

Learn more about the use of lucibufagins by reading this article

However, you're probably still wondering "How exactly does that lighting up work?".....  Well curious zoophile, read on for the asnwer!

The cells in the lower abdomen of the firefly are specially adapted to produce light (Timmins, 2001). These cells contain a chemical called luciferin which is then used to produce an enzyme called luciferase. When luciferin mixes with oxygen something callled oxyluciferin is formed. When oxyluciferin is produced, light is one of the by products of the reaction (Viera, 2012). That's how their rear ends glow!

For a more in depth look at the chemical reaction that's taking place, check out this really helpful link by How Stuff Works