I am a PhD student working in applied probability theory. I have submitted my PhD thesis and started to apply for postdoc positions.
Is it OK to ask a professor whether they have a position available? If so, what should such an e-mail contain?
Yes, it is fine. It never hurts to ask. Some people will ignore you, but some people will reply.
I advise you to have this conversation in person and not via email.
When you are face to face with this professor you will be able to read their body language. If you ask the question and they appear annoyed or uncomfortable then just end the conversation quickly and politely. If, however, you see they show interest, then you may inquire further.
When setting up the initial meeting, you can write a simple email stating who you are and asking what times the professor is available to speak with you.