Old PI's coauthorship on a paper after finishing the postdoc, a preliminary idea developed then but rejected by him I understand that according the ethical rules, obtaining the funding does not automatically entitle the principal investigator (PI) for authorship. But I don't understand the unwritten rules. 

I was on a postdoc. During the postdoc, I was paid from a grant obtained by the PI. At the beginning, he told me to find a good research topic and write a paper ("this will be your child"). I spent some time on literature search and very preliminary computations. I presented my idea to the PI but he told he doesn't want me to continue this topic. He even repeated this several times, on different occasions. He said my idea was too losely connected to what his group was doing. So I gave up that topic and did not do it any longer. Finally, I published a paper on quite different topic, together with the group members, and the PI was also a co-author. 

One day I talked to a colleague from that group and I mentioned my old research idea. I said I would like to develop it anyway, when I finish the current postdoc. He told me that the PI should still be a co-author because I spent some time working on this idea in his group and I was paid by his money.

Now, it's been a couple of years since I finished that postdoc. I have independence and I can publish myself as the corresponding author. I would like to publish a paper on the idea I once had. Should I somehow credit the old PI? (And his grant? It's over already.) 

The whole idea of the research is mine. The PI did not contribute whatsoever to it. I feel that crediting someone just for his funding is not ethical. The more so that he rejected my idea. But I understand the words of that colleague as a sort of a warning because he has been working with the PI for a long time and probably he knows his attitide. And that guy (the old PI) is quite well-known person in the community. Do you think I should somehow negotiate with him? Or stick at nothing and just publish the paper as entirely mine?
I cannot see why the former PI should have co-authorship on a paper they did not support or had any interest in. You are not a slave (or at least should not be) when on a post-doc (or any other position) and should retain the freedom to take own initiatives. As long as you fulfil any obligations within the position you are holding, no-one can prevent you from developing your own ideas. I can see an issue if you use materials that involve costs that you are not covering, for example, lab equipment or chemicals, electronic resources that removes capacity or resources otherwise used by the project. I do not count, for example, using a computer and printouts as such resources.

So, for me there is no question you can use the research as your own and you should add only authors that fulfil reasonable contributorship criteria, that is have contributed to the science of your work (see posts under the authorship tag for such criteria).