Ripples and impurity atoms are universally present in 2D materials, limiting carrier mobility, creating pseudo–magnetic fields, or affecting the electronic and magnetic properties. Scanning transmission electron microscopy (STEM) generally provides picometer-level precision in the determination of the location of atoms or atomic 'columns' in the in-image plane (xy plane). However, precise atomic positions in the z-direction as well as the presence of certain impurities are difficult to detect. Furthermore, images containing moiré patterns such as those in angle-mismatched bilayer graphene compound the problem by limiting the determination of atomic positions in the xy plane. Here, we introduce a reconstructive approach for the analysis of STEM images of twisted bilayers that combines the accessible xy coordinates of atomic positions in a STEM image with density-functional-theory calculations. The approach allows us to determine all three coordinates of all atomic positions in the bilayer and establishes the presence and identity of impurities. The deduced strain-induced rippling in a twisted bilayer graphene sample is consistent with the continuum model of elasticity. We also find that the moiré pattern induces undulations in the z direction that are approximately an order of magnitude smaller than the strain-induced rippling. A single substitutional impurity, identified as nitrogen, is detected. The present reconstructive approach can, therefore, distinguish between moiré and strain-induced effects and allows for the full reconstruction of 3D positions and atomic identities.