You have asked a classic question in biology, and of course, a very important one. How living things produce usable energy is important not only from the perspective of understanding life, but it could also help us to design more efficient energy harvesting and producing products - if we could "mimic" how living cells deal with their energy balance, we might be able to vastly improve our technology. For example, a plant is a much better harvester of sunlight than even our best solar panel. And of course, if we understand energy use, it can also help us deal with human diseases such as diabetes.
Now, the answer to your question can be found in any basic biology text book, but sometimes, there is so much information packed into such a text book that it can be difficult to extract the information you need or more often, to view all of that information in a larger context. Let's try to tackle your question in several parts.
First, we need to know what ATP really is - chemically, it is known as adenosine triphosphate. ATP is a usable form of energy for cells - the energy is "trapped" in a chemical bond that can be released and used to drive other reactions that require energy (endergonic reactions).
Photosynthetic organisms use energy from sunlight to synthesize their own fuels. They can convert harvested sunlight into chemical energy (including ATP) to then drive the synthesis of carbohydrates from carbon dioxide and water. When they synthesize the carbohydrates, oxygen gets released. Globally, more than 10 billion tons of carbon is "fixed" by plants every year - this means that carbon molecules are converted from being part of a simple gas (carbon dioxide) into more complex, reduced molecules (carbohydrates), making carbon available as food for non-photosynthesizers (and of course, providing oxygen). They use some of the carbohydrate for their own growth and reproduction. It is pretty remarkable when you think about it - have you been to Sequoia National Park or seen the redwoods along our northwest coast? Massive trees, right? Think about the fact that most of that mass is in the form of carbon that was pulled out of the air as carbon dioxide!
The process of photosynthesis is two-part. First, there are the light reactions, where light is converted into chemical energy (a reduced electron carrier and ATP). This occurs in the thylakoids (stacked membranes) of the chloroplasts. The ATP and electron carriers are then used in a second set of reactions, called the light-independent reactions. This also occurs in the chloroplasts, but in an area called the stroma. In this case, carbon dioxide gets used to produce sugars in a series of reactions called the Calvin Cycle, C4 photosynthesis, and crassulacean acid metabolism. You can look in any basic bio textbook to see how much "energy" or "sugar" is produced in each step of the process.
In non-photosynthesizers, the fuel has to be consumed. The most common chemical fuel is the sugar glucose (C6H12O6)... Other molecules, such as fats or proteins, can also supply energy, but (usually) they have to first be converted to glucose or some intermediate that can be used in glucose metabolism.
Now this brings us to the next part - how do we go from glucose to ATP? This is achieved through the process of "oxidation" - and this is carried out through a series of metabolic pathways. Complex chemical transformations in the cell occur in a series of separate reactions to form each pathway, and each reaction is catalyzed by a specific enzyme. Interestingly, metabolic pathways are similar in all organisms, from bacteria to humans. In eukaryotes (plants and animals) many of the metabolic pathways are compartmentalized, with certain reactions occurring in specific organelles. Basically, cells trap free energy released from the breakdown (metabolism) of glucose. This energy gets trapped in the ATP as it converts from ADP to ATP by the addition of phosphate.
There are 3 main pathways for harvesting energy from glucose:
Glycolysis - begins glucose metabolism in all cells to produce 2 molecules of pyruvate. Occurs outside of mitochondria, usually in cytoplasm.
Cellular Respiration - uses oxygen from the environment and converts each pyruvate to three molecules of carbon dioxide while trapping the energy released in this process in ATP. There are 3 sub-pathways of cellular respiration - pyruvate oxidation, the citric acid (Krebs or Tricarboxylic Acid) cycle and the electron transport chain. Occurs in different sub-compartments of mitochondria.
Fermentation - converts pyruvate into lactic acid or ethanol; does not need oxygen. It is not as efficient as cellular respiration; it occurs in the cytoplasm.
In terms of how much ATP is produced, you can look in your basic texts and assess how many ATPs are used versus how many are produced for each aspect of metabolism