Ellen J. Prager, assistant dean of the University of Miami's Rosensteil School of Marine and Atmospheric Science and author of The Oceans (McGraw-Hill, 2000), offers this explanation:

Ellen J. Prager
Ellen J. Prager

A number of cephalopods--the group of animals that includes octopuses, squid and cuttlefish--are skilled in the art of color change, which can be used for camouflage or to startle and warn potential predators in their undersea realm. Many of these creatures have special pigment cells called chromatophores in their skin. By controlling the size of the cells they can vary their color and even create changing patterns. Chromatophores are connected to the nervous system, and their size is determined by muscular contractions. The cephalopods also have extremely well developed eyes, which are believed to detect both the color and intensity of light. Using their excellent eyesight and chromatophores, cephalopods camouflage themselves by creating color patterns that closely match the underlying seafloor. In squid, color changes also occur when the animal is disturbed or feels threatened.

In addition to color control, many of the squid can produce light and control its intensity. Biologically produced light is called bioluminescence, and it is used for a wide variety of purposes by marine organisms. Some creatures are believed to use bioluminescence to confuse or startle predators, others may stun their prey, and some use it as a decoy to facilitate escape or as a lure to attract the unwary. Bioluminescence may also offer a means of communication in the dim midwater or twilight region of the sea.

deep-dwelling squid Histioteuthis Heteropsis
The deep-dwelling squid Histioteuthis Heteropsis is covered with photophores, perhaps used to mask its silhouette from predators and prey.

Squid and other marine creatures create light by mixing two substances into a third that gives off light, similar to the mechanism by which a common firefly lights up or the way the popular plastic green glow-sticks work. To get a glow-stick to "glow," it is bent. This causes the two chemicals inside to mix and react, yielding a third substance that gives off light. Within an organism¿s special light-producing cells (photocytes) or organs (photophores), essentially the same thing happens. A substance called luciferin reacts with oxygen in the presence of an enzyme, luciferase. A new molecule forms when the reaction is complete, and in the ocean it typically glows blue to green in color. In some organisms the photophores are simple glandular cups. In others they are elaborate devices with lenses for focusing, a color filter, or an adjustable flap that serves as an off/on switch. Squid that have both photophores and chromatophores within their skin can control both the color and the intensity of light produced. Research has also revealed that within some squid and fish, bioluminescent light may be produced by bacteria that live inside the animal¿s light organs.