Bioapatite is the mineral component of bones and teeth.
Apatite is a general term for a group of minerals made of calcium phosphate. Different apatite minerals have differing amounts of other elements and atomic groups like fluorine (-F), hydroxyl (-OH), and carbonate (-CO3). Bones and teeth are composed of tiny crystallites of minerals in the apatite mineral group. For simplicity, we just refer to any apatite mineral in bones and teeth as bioapatite, so we don’t have to argue about what the precise composition of the apatite mineral is.
Rocks, by definition, are naturally forming aggregates of mineral grains and organic detritus. This means, that in a very loose sense, bones and teeth could be considered rocks, which would explain why they fossilize so well.
Oxygen and carbon may be incorporated into bioapatite as the bones grow or the teeth form. The relative amounts of heavy to light isotopes of oxygen and carbon reflect the environment (oxygen) and the diet (carbon) of the animal while the minerals are growing. These isotopic ratios are then preserved in the bioapatite crystals even after the animal is dead and fossilized. From this, geochemists can later extract information about the ancient environment in which the animal lived and better understand what the Earth of the past was like.