It is extremely rare for conditions to be right for formation of fossils; and even more rare for opalised fossils to form. Usually, only the hard parts of living things fossilise for example seed pods, wood, teeth, bones and shells. This often happens after the plant or animal (or a part of it) is buried in sand or other sediments that slowly turn to stone.
Opal forms in cavities within rocks. If a cavity has formed because a bone, shell or pinecone was buried in the sand or clay that later became the rock, and conditions are right for opal formation, then the opal forms a fossil replica of the original object that was buried. We get opalised fossils of two kinds:
1) Internal details not preserved: Opal starts as a solution of silica in water. If the silica solution fills an empty space left by a shell, bone etc that has rotted away like jelly poured into a mould it may harden to form an opalised cast of the original object.
Most opalised shell fossils are 'jelly mould' fossils the outside shape is beautifully preserved, but the opal inside doesnt record any of the creatures internal structure.
2) Internal details preserved: If the buried organic material hasnt rotted away and a silica solution soaks into it, when the silica hardens it may form an opal replica of the internal structure of the object. This happens sometimes with wood or bone.
http://www.geologypage.com/2017/04/opalised-fossils-form.html
Great. Now I'll have that ELO song stuck in my head all day...