Coal, oil, and natural gas are composed of fossils—that is, the remains of organisms that lived as long ago as 500 million years. Oil and gas originated as organisms in the oceans, such as phytoplankton, that over time became incorporated into the sediments on the ocean floor.
Coal is the fossilized remains of trees and other plants that were buried in the Earth. Over millions of years, these remains were subjected to pressure, temperature, and chemical processes to become transformed into coal.
Source: Ojakangas, Richard. Schaum's Outline of Theory and Problems of Introductory Geology, p. 78.