We study how maximum output power can be obtained from a thermoelectric generator (TEG) with non-ideal heat exchangers. We demonstrate with an analytic approach based on a force-flux formalism that the sole improvement of the intrinsic characteristics of thermoelectric modules including the enhancement of the figure of merit is of limited interest: the constraints imposed by the working conditions of the TEG must be considered on the same footing. Introducing an effective thermal conductance we derive the conditions which permit maximization of both efficiency and power production of the TEG dissipatively coupled to heat reservoirs. Thermal impedance matching must be accounted for as well as electrical impedance matching in order to maximize the output power. Our calculations also show that the thermal impedance does not only depend on the thermal conductivity at zero electrical current: it also depends on the TEG figure of merit. Our analysis thus yields both electrical and thermal conditions permitting optimal use of a thermoelectric generator.