Contact a professor to agree a research proposal for a post doc position that he is advertising I am a PhD candidate in computer science and I am looking for postdocs.

Surfing the web, I have found a post-doc opening that I find extremely interesting, but I do not know personally the PI of the group, nor my advisor does. 

The opening asks for submitting 3 items: a CV, a cover letter and a research proposal.

Before writing a research proposal I would like to get in contact with the PI and try to understand their challenges and write something that would be meaningful for them, instead of going directly with a proposal that maybe is not of interest for them.

Which is the best way to approach a PI in this setting? Should I send him a mail with a CV and referee contacts even if this is not exactly an application, but is an informal query? Or should I go directly with the formal application?

Any experience to share?
A postdoc application process is not a competition to find which person can magically understand the PI's objectives, it is there to find the best fit for the job. On the other hand, a postdoc is the start of independent research. You should devise your own research agenda(s) and ask questions about the suitability of your ideas to get a better feel for the project.

In my direct experience and experience of people in a similar position, it is entirely normal to ask questions about the position beforehand. Have a look at the advertisement, it may even explicitly mention to email any questions. My recommendation is to email the PI with a very short description of yourself (research area, where you got your PhD from, etc.) and very short questions. If - this - job is not suitable, the PI may even have you in mind for something else.

In my case I emailed asking if there was scope to do X (there was) for a job in an entirely new field, it is the best position I've ever applied for and I wouldn't have if I had not known it was possible.