The operation of water distribution systems impacts the water quality in these systems. EPA regulations require that water quality be maintained at all points in the system including the point of delivery. Methods to optimize water system operations have been restricted to reducing costs related to pumping and costs related to sizing, construction and/or maintenance of piping while meeting customer demands, pressure limits, and tank operation restrictions. There have been few attempts to optimize water system operations for both hydraulic and water quality performance and they have been restricted to simplified systems. A new methodology that formulates the water distribution system problem as a discrete time optimal control problem was developed which linked the method of simulated annealing with EPANET for optimal operation of water distribution systems for both water quality and hydraulic performance. Most optimization techniques require the calculation of derivatives, response functions, or other methods that are limited to specific problems. Simulated annealing allows optimization for a variety of objective functions and can consider many modifications to operational conditions without reprogramming of the optimization procedure. The new methodology was applied to the North Marin Water District, Novato, California system which considered optimal pump operation for minimizing power costs while meeting hydraulic and water quality constraints.