Improvement of thermoelectric systems in terms of performance and range of applications relies on progress in materials science and optimization of device operation. In this chapter, we focus on optimization by taking into account the interaction of the system with its environment. For this purpose, we consider the illustrative case of a thermoelectric generator coupled to two temperature baths via heat exchangers characterized by a thermal resistance, and we analyze its working conditions. Our main message is that both electrical and thermal impedance matching conditions must be met for optimal device performance. Our analysis is fundamentally based on linear nonequilibrium thermodynamics using the force-flux formalism. An outlook on mesoscopic systems is also given.