When should the term "pan-pan" be used instead of "Mayday"?
Oddly enough, the FARs and the AIM do not define these terms even though they use them frequently, but it is in the Pilot Controller Glossary (see below).  This is one of those areas that I've never really been given specific training on and I guess figured that I would "know it when I saw it".  The definitions kind of support that since they leave it to the discretion of the pilot:


  EMERGENCY- A distress or an urgency condition.
  
  DISTRESS (MAYDAY)- A condition of being threatened by serious and/or imminent
  danger and of requiring immediate assistance.
  
  URGENCY (PAN-PAN)- A condition of being concerned about safety and of requiring
  timely but not immediate assistance; a potential distress condition.


Flight Safety released a report titled Use of Standard Phraseology by Flight Crews and Air Traffic Controllers Clarifies Aircraft Emergencies which includes a quote from an official in which she says that there is a misconception among some pilots about the difference between declaring mayday and pan-pan:


  I have observed many cases where a mayday is given when pan-pan should
  be sufficient.  Many pilots do not realize that this distinction is
  ATC's way of prioritizing two or more aircraft with an emergency at
  the same time.


She also included some of the most important factors to consider when deciding to declare an emergency:


  
  Is the aircraft in immediate danger?
  Does the aircraft require immediate assistance?
  Will the aircraft require priority handling during the approach or during any other phase of flight?
  Will the aircraft need special assistance on the ground?
  Does the crew need any assistance from other parties?
  


The most important thing though is not whether you declare exactly the right kind of emergency, but that you actually let them know when you need help.  Don't forget that you can also change your mind.  If you declared an Urgency condition and decide that you need more assistance/priority, you can always "upgrade" it to a Distress, and vice-versa.