The teens in our biology lab are learning about this, so I thought you might want to too. Here's the simplified view:
Plants produce their own food (sugars) using carbon dioxide, water, and sunlight. Oxygen is a by-product of this reaction.Then, we (or herbivores or other omnivores) eat the plants to get their sugar and breathe in oxygen which creates energy (for living), as well as by-products of carbon dioxide and water.
The chemistry gets far more complex than this! :}
"I may not have gone where I intended to go, but I think I have ended up where I needed to be." ~ Douglas Adams