I recently reviewed a paper (general applied mathematics context). During the review, I realized that the fairly general ideas introduced in the paper can potentially be applied to a specific problem in a similar context. The authors did not mention this application in their paper, so I suggested to add a short comment about it in my review.
I later started thinking about the application in more detail and tried out some things, which actually seem to work quite well for this application. Now, the paper is still in the review process and might take some time until it gets published. What is the proper way how to proceed here in order to use the ideas and results which I in my exclusive position as a reviewer saw? How can I refer to the paper that is still under review? How can I best discuss the ideas with my co-workers (and potential co-authors) without disclosing that I reviewed the paper?
The paper under review is not available online on any preprint servers such as arXiv etc
You can't ethically do anything based on ideas from this paper until it is made public (by the authors as a preprint, or by the publisher). In particular, before that point you can't refer to the paper, you can't use the ideas without referring to it, you can't publish or otherwise disseminate results based on it, and you can't discuss it with other people, including your collaborators. It can be really frustrating to know something important and be unable to tell anyone else for the time being, but there's no way around it ethically.
The reason is that submitting a paper for publication is not considered to release it for other use or dissemination until it is actually published. The people involved in processing and evaluating it (most notably the editors and reviewers) have an ethical obligation to keep all information about the submission strictly confidential and not to use it to gain any personal advantage. Once it is published of course it can be treated the same as any other paper, and in the meantime the authors can choose to make information publicly available via preprints or talks (in which case others can follow up on this information as appropriate), but nobody else is authorized to release any information before publication beyond what the authors have chosen to share, or to use it for any purpose other than reviewing the paper. Otherwise it has the same ethical status as using material you stole off the authors' desks.
There's no reason why the research community has to work this way in principle, but it's the system that has evolved over time. (Note that as recently as the 1930's, famous physicists were not all in agreement as to how peer review should work.) It's possible that in the future we will move to systems such as submitting for publication only after releasing a preprint. That seems to be the trend in some fields, but we haven't yet made a full transition if we ever will, and the community's ethical principles still offer protection to authors who choose not to distribute their paper before publication.
Nobody signs a non-disclosure agreement when reviewing a paper, but the ethical principles are well established. Deliberately violating them would be a serious form of misconduct, which could easily be career-ending if it was more than a minor or technical violation.
Pete L. Clark asks in the comments whether referees are allowed to prepare follow-up papers, as long as they don't distribute them before the original paper becomes public. I.e., does the "you can't ethically do anything based on ideas from this paper" really mean you can't do anything, or just that you can't disseminate anything yet? (Let's assume it's a single-authored paper that is not discussed with anyone else in advance.) My interpretation is that nobody can stop you from thinking a little, and you may not even be able to stop yourself, but actively working on and writing a paper of your own would be abusing your position as referee. There probably isn't a consensus as to exactly where the line is for what's strictly forbidden, but either side of the line could still look terrible. If you want to publish work you began thinking about as a referee, I'd strongly recommend against doing it so quickly that's it clear you had to have known about the original paper in advance.