As others have noted, there are different sorts of stuck. One that hasn't been addressed much by the other answers is the sort where you want to work on a problem, and you have time and energy, you just don't have an idea on how to make progress. In this situation, in addition to all the great advice in "How to Solve It", I can add two techniques that've worked for me: reading (or re-reading) related papers, and writing code.
Often, in the process of writing code to actually compute a nice example, or verify one, or automate some aspect of what's happening, I get into a different head-space that helps me to understand the nature of the difficulty. Also, other interesting closely related problems are forced in front of me, so that I have more things to think about.