What temperature should I set my water heater to?
There are two main and opposing risks:


Too high, and users get scalded 
Too low, and you risk pathogens, particularly Legionella bacteria, which causes legionellosis (Legionnaires' disease)


Minimum temperature

Legionella risk

According to the paper "Legionella and the prevention of legionellosis," found at the World Health Organization website, temperature affects the survival of Legionella as follows:


Above 70 °C (158 °F) - Legionella dies almost instantly
At 60 °C (140 °F) - 90% die in 2 minutes
At 50 °C (122 °F) - 90% die in 80–124 minutes, depending on strain
48 to 50 °C (118 to 122 °F) - Can survive but do not multiply
32 to 42 °C (90 to 108 °F) - Ideal growth range


Dishwashers

Most current-model dishwashers have a minimum requirement of 49 °C (120 °F). Most have heaters and will heat the interior as needed. If yours is older you may want to check specifications.

Dishwasher detergent varies, but "works best between 50 and 60 °C" seems to be a fairly common statement. There is also cold-water detergent on the market that works at basically any temperature. 

Maximum temperature

Burn risk

Setting too high can scald someone using the water. This is particularly easy because when you first open the tap, the water in the pipes has cooled down some, and so its temperature will rise (possibly dramatically) once the water from the tank reaches the point of use. 

Young children are at higher risk because their skin is thinner. Some people, especially the elderly, are at higher risk because they may be less sensitive and slower to move away from scalding water.


The Consumer Product Safety Commission (CPSC) recommends setting to 49 °C (120 °F) 


Piping Concerns

From LegionellaPrevention.o:

Dead legs

Dead legs (branches that are capped off or rarely used) contain stagnant water that can be an ideal breeding ground for bacteria which can contaminate the entire system. This should not be surprising as the water in the dead leg would get warm, but never hot to the temperature of the main flow.


If unavoidable, a valve should be installed as close to the main line as possible (no more than 1 pipe diameter away) to minimize risk. 


PEX vs Copper

In a study, Legionella seemed to grow a bit faster in PEX than copper (over a period of 500 days), however, over a period of 800 days there was essentially no difference in growth and both pipes had identical biofilms formed inside them. 

Copper in theory would cool down faster than PEX (Ed: I can't find any studies on this) but given enough time (likely a couple hours), the temperature of both would cool to the ambient temperature. There's a separate question that discusses if it's worthwhile to insulate pipes, but even with insulation, the water in the pipes will eventually cool to ambient.


PEX vs Copper is irrelevant




Conflicting Views

From Heated Debate about Hot Water:


  The country’s top experts, represented on the Canadian Commission on Building and Fire Codes (CCBFC), have rejected the lower maximum hot water tank temperature of 49 °C. In spite of this, trusted organizations are telling homeowners to lower their hot water tank temperature to 49 °C as a precaution against scalds from tap water. Some even offer tips on how to find the thermostat so you can adjust it yourself. 
  
  The bottom line is that water must be stored at a high temperature as a precaution against bacteria. It can be delivered from the tap at a lower temperature to prevent scalds. 


Conclusion

The article Residential water heater temperature: 49 or 60 degrees Celsius? published in the Canadian Journal of Infectious Diseases concludes:


  In our opinion, it is important to reduce both the risk of scalds and the risk of legionellosis associated with domestic water supplies.
  
  For water heaters servicing a single housing unit:
  
  
  Electric water heaters should be set at 60 °C to limit the risk of Legionella contamination, and equipped with anti-scald devices to deliver water at 49 °C to the entire household.
  Gas or oil water heaters should be set at 49 °C, because the risk of scalding is greater with these devices. 
  
  
  For water heaters servicing multiple unit housing complexes:
  
  
  More complex water distribution systems are more likely to be contaminated, and the recommendations from the WHO should apply no matter what type of water heater is used: hot water must be stored at 60 °C inside the water heater by ensuring, at least once a day, the temperature reaches at least 60 °C in the entire tank. 
  
  
  Moreover, water should reach the tap at a temperature of at least 50 °C. 
  Taps in these buildings, especially in the bath or shower where most scalds occur, should be equipped with anti-scald devices to decrease the water temperature to 49 °C or less.
  
  


Absolute Ideal Scenario

The best scenario seems to be to install anti-scald mixing valves at each human point of use (e.g., sinks, tubs): whether it be integrated in a shower valve, or installed under the sink.


The tank gets set to the WHO-recommended 60 °C. 
Each human point-of-use is limited to the CPSC-recommended 49 °C (120 °F)


You may even want it lower (e.g., 110 °F) in kid's bathrooms. 

Other uses -- dishwasher, washing machine, humidifier -- can get the full 60 °C with no issue.


The downside to this, of course, is cost: you need to install the valves on each hot water tap. For sinks, this is relatively easy to retrofit; for tubs/showers it may be more difficult.