Is it appropriate as a referee to contact an author after the editor rejected the manuscript?
One important consideration is whether the paper is publicly available (for example, being circulated on the web as a preprint).  If it is, then it's perfectly reasonable to get in touch with the authors and offer suggestions.  You don't need to address the question of how you heard about the paper if you don't want to.  If you do want to reveal yourself as a reviewer, I think it's fine, but I've run across people who disagree about this.

It's much trickier if the existence of the paper is itself confidential.  If for some reason I submitted a paper without circulating it publicly, and then after rejection a referee contacted me privately with detailed suggestions for improvement, I would feel uncomfortable.  It would look a little too much like an attempt to become involved in the research or writing, and I would wonder whether the referee might take offense if I just said "thanks for the suggestions" and didn't engage in further discussion or collaboration.

If you have confidential knowledge about a paper, then you must not even appear to be using it for your own benefit.  For example, you can't ask to start a collaboration or try to find out more about this research.

If there's no public preprint, then it's safest to make contact through the editor, and at the very least you should ask the editor about what you intend to do (the editor may well object, and in any case you need to avoid seeming secretive about it).  Even if the editor approves, you should be careful, since innocent actions may be misinterpreted.