The energy of harmonic sections of flat bundles of nonpositively curved (NPC) length spaces over a Riemann surface S is a function E-rho on Teichmuller space T-S which is a qualitative invariant of the holonomy representation rho of pi(1) (S). Adapting ideas of Sacks-Uhlenbeck, Schoen-Yau and Tromba, we show that the energy function E-rho is proper for any convex co-compact representation of the fundamental group. More generally, if rho is a discrete embedding onto a normal subgroup of a convex cocompact group Gamma, then E-rho defines a proper function on the quotient T-S/Q where Q is the subgroup of the mapping class group defined by Gamma/rho(pi(1)(S)). When the image of rho contains parabolic elements, then E-rho is not proper. Using the theory of geometric tameness developed by Thurston and Bonahon [5], we show that if rho is a discrete embedding into SL(2, C), then E-rho is proper if and only if rho is quasi-Fuchsian. These results are used to prove that the mapping class group acts properly on the subset of convex cocompact representations.