Exerpts taken from Wikipedia: http://en.wikipedia.org/wiki/Bioluminescence
There are five main theories for bioluminescent traits:
In some species bacterial bioluminescence is used for counterillumination so the animal matches the overhead environmental light
The cookiecutter shark uses bioluminescence for camouflage, but a small patch on its underbelly remains dark and appears as a small fish to large predatory fish like tuna and mackere lswimming beneath it. When these fish try to consume the "small fish", they are bitten by the shark, which gouges out small circular "cookie cutter"-shape chunks of flesh from its hosts. Bioluminescence is used as a lure to attract prey by several deep sea fish such as the anglerfish. A dangling appendage that extends from the head of the fish attracts small animals to within striking distance of the fish. Some fish, however, use a non-bioluminescent lure.
Dinoflagellates have an interesting twist on this mechanism. When a predator of plankton is sensed through motion in the water, the dinoflagellate luminesces. This, in turn, attracts even larger predators that will consume the would-be predator of the dinoflagellate.
The attraction of mates is another proposed mechanism of bioluminescent action. This is seen actively infireflies, which use periodic flashing in their abdomens to attract mates in the mating season. In the marine environment, this has been well documented only in certain small crustaceans called ostracod. It has been suggested that pheromones may be used for long-distance communication, and bioluminescence used at close range to "home in" on the target.
Certain squid and small crustaceans use bioluminescent chemical mixtures or bioluminescent bacterial slurries in the same way as many squid use ink. A cloud of luminescence is expelled, confusing or repelling a potential predator while the squid or crustacean escapes to safety. Every species of firefly has larvae that glow to repel predators.
Communication between bacteria (quorum sensing) plays a role in the regulation of luminesence in many bacterial species. Using small extracellularly secreted molecules, they are able to adapt their behavior to turn on genes for light production only when they are at high cell densities.