We derive policy implications for an inflation targeting central bank, whose credibility is endogenous and depends on its past ability to achieve its targets. We do this in a New Keynesian framework with heterogeneous agents and boundedly rational expectations. Our assumptions about expectation formations are more in line with expectations observed in survey data and laboratory experiments than the fairly restrictive rational expectations hypothesis. We find that the region of allowed policy parameters is strictly larger under heterogeneous expectations than under rational expectations. Furthermore, with theoretically optimal monetary policy, global stability of the fundamental steady state can be achieved, implying that the system always converges to the targets of the central bank. This result however no longer holds when the zero lower bound (ZLB) on the nominal interest rate is accounted for. Self-fulfilling deflationary spirals can then occur, even under optimal policy. The occurrence of these liquidity traps crucially depends on the credibility of the central bank. Deflationary spirals can be prevented with a high inflation target, aggressive monetary easing, or a more aggressive response to inflation.