The study of the interactions between organisms and their environments, including past and present ecosystems.