We propose a new formalism and an effective computational framework to study self-trapped excitons (STEs) in insulators and semiconductors from first principles. Using the many-body Bethe-Salpeter equation in combination with perturbation theory, we are able to obtain the mode- and momentum-resolved exciton-phonon coupling matrix element in a perturbative scheme and explicitly solve the real space localization of the electron (hole), as well as the lattice distortion. Further, this method allows us to compute the STE potential energy surface and evaluate the STE formation energy and Stokes shift. We demonstrate our approach using two-dimensional magnetic semiconductor chromium trihalides and a wide-gap insulator BeO, the latter of which features dark excitons, and make predictions of their Stokes shift and coherent phonon generation which we hope will spark future experiments such as photoluminescence and transient absorption studies.