In this paper we introduce a new kind of Backward Stochastic Differential Equations, called ergodic BSDEs, which arise naturally in the study of optimal ergodic control. We study the existence, uniqueness and regularity of solution to ergodic BSDEs. Then we apply these results to the optimal ergodic control of a Banach valued stochastic state equation. We also establish the link between the ergodic BSDEs and the associated Hamilton-JacobiBellman equation. Applications are given to ergodic control of stochastic partial differential equations.