The age they were formed is called the Carboniferous period, getting its name from carbon the basic element in coal and other fossil fuels. Fossil fuels are made up of decomposed plant and animal matter.
Plants change energy they receive from the sun into stored energy.
This energy is food used by the plant. This is called photosynthesis. Animals eat plants to make energy. And people eat animals and plants to get energy to do work. When plants and other ancient creatures died, they decomposed and became buried, layer upon layer under the ground.