We don't know the exact number, but we do know that it is in the millions of years.
In the 1984 cartoon series, the Aerialbots travel 9 million years to the past and meet Orion Pax and witness him being rebuilt into Optimus Prime. So if we consider Optimus's age just from that point onward then he's 9 million years old and possibly much older if we figure in his time as Orion. However, he was in stasis on Earth when the Ark crashed for around 4 million years. So let's call him 5 million years old.
In the IDW comics continuity, the earliest mention of Orion Pax was him as a police officer serving Nominus Prime, then he becomes Optimus Prime during the reign of Zeta Prime. We don't have any dates. But we do know that Nova Prime (who predated all of those Primes) left Cybertron 6 million years ago. We also know from Transformers #22 that Optimus Prime and Megatron engaged in the battle of Sherma Bridge 4 million years ago. So his age as Optimus Prime is between 4-6 million years, and again could be much longer if we figure out his time as Orion Pax.