Most of us learned in school that plants produce oxygen and consume carbon dioxide, while animals (like us) consume organic matter (such as carrots and burritos) and oxygen and produce carbon dioxide. These relationships keep our planet in a nice balance for both plants and animals. They are easy to remember, but leave out some interesting parts of the story.
Living things need energy to maintain order — blossoms, membranes, beating hearts — in the face of the forces of entropy and chaos. Plants get energy from the sun, producing oxygen and consuming carbon dioxide in the process. We get energy from the food that we eat, which ultimately comes from sunlight by way of plants.
But these are not the only sources of energy that living things can use. In the Earth's many secret places, like swamp soils, deep lakes and ocean sediments, there is no oxygen at all, but bacteria, fungi and even a few animals still are able to consume organic matter — dead bits of plants, animals and other bacteria. Instead of taking in oxygen, they "breathe" nitrate or sulfate or iron. They produce carbon dioxide, too, but also substances like nitrogen gas or sulfide or methane.
You may never have heard of such species, but you are familiar with their work. The wine we drink and the rotten-egg smell of pond mud are products of organisms that live and work in habitats without oxygen.
What is essential for life is not that there is oxygen to breathe or organic matter to eat, but that there is an energy source. The list of possible chemical reactions that could be exploited for energy capture is long, and enterprising organisms survive using dozens of chemical reactions other than the simple oxygen-carbon dioxide reactions of the typical biology textbook. And not all photosynthesis produces oxygen, either, but that's a story for another time.
It seems odd to think life can exist without oxygen, but the earliest forms of life on our planet did not need it. In fact, there wasn't even any oxygen in the Earth's atmosphere until about 2.5 billion years after life arose. When oxygen first began appearing on Earth as a product of photosynthesis, it was a deadly poison to early life forms. However, through the long process of natural selection, most living things have evolved to tolerate oxygen — and even benefit from it.
Here are two important lessons about the versatility of life. First, these unfamiliar organisms that live without oxygen are essential to the persistence of life on Earth. If all consumers required oxygen, all the dead material in the Earth's many oxygen-free zones would simply pile up there, unable to decay.
Second, you should be able to see now why it is so hard to tell whether there is life on another planet. What would you look for? Living things don't necessarily produce oxygen or carbon dioxide, and they don't necessarily need water or carbon, or any other single substance. They need to be able to capture energy to maintain some kind of order against the chaos of the universe. The ways in which they capture this energy could be fantastically varied, depending on the opportunities offered by some alien planet.
Life is so complex that it is unreasonable to think we could learn all about it in school. It does seem a pity that many textbooks leave out some of the best parts.