The species in ecosystems are mutually interacting and self sustainable stable for a certain period. Stability and dynamics are crucial for understanding the structure and the function of ecosystems. We developed a potential and flux landscape theory of ecosystems to address these issues. We show that the driving force of the ecological dynamics can be decomposed to the gradient of the potential landscape and the curl probability flux measuring the degree of the breaking down of the detailed balance (due to in or out flow of the energy to the ecosystems). We found that the underlying intrinsic potential landscape is a global Lyapunov function monotonically going down in time and the topology of the landscape provides a quantitative measure for the global stability of the ecosystems. We also quantified the intrinsic energy, the entropy, the free energy and constructed the non-equilibrium thermodynamics for the ecosystems. We studied several typical and important ecological systems: the predation, competition, mutualism and a realistic lynx-snowshoe hare model. Single attractor, multiple attractors and limit cycle attractors emerge from these studies. We studied the stability and robustness of the ecosystems against the perturbations in parameters and the environmental fluctuations. We also found that the kinetic paths between the multiple attractors do not follow the gradient paths of the underlying landscape and are irreversible because of the non-zero flux. This theory provides a novel way for exploring the global stability, function and the robustness of ecosystems.