Twisted bilayers of two-dimensional materials, such as twisted bilayer graphene, often feature flat electronic bands that enable the observation of electron correlation effects. In this work, we study the electronic structure of twisted transition metal dichalcogenide (TMD) homo-and heterobilayers that are obtained by combining MoS2, WS2, MoSe2 and WSe2 monolayers, and show how flat band properties depend on the chemical composition of the bilayer as well as its twist angle. We determine the relaxed atomic structure of the twisted bilayers using classical force fields and calculate the electronic band structure using a tight-binding model parametrized from first-principles densityfunctional theory. For homobilayers, we find that the two highest valence bands exhibit a graphenelike dispersion and become flat as the twist angle is reduced. In contrast, not all heterobilayers have flat valence bands. Specifically, we find that those systems in which the highest valence band derives from K or K' states of the constituent monolayers do not exhibit flat bands, even at small twist angles. In all systems, qualitatively different band structures are obtained when atomic relaxations are neglected.