Cloud computing services are becoming integral part of people's daily life. These services are supported by Internet data centers (IDCs). As demand for cloud computing services soars, energy consumed by IDCs is skyrocketing. This paper studies an energy management problem -- how to minimize energy cost for IDCs in deregulated electricity markets. While several existing works handle this problem by leveraging spatial diversity of electricity price, little has been done to address the temporal uncertainty in electricity price and arriving workload. This paper proposes a novel two-stage design and the eco-IDC (Energy Cost Optimization-IDC) algorithm to exploit temporal diversity of electricity price and dynamically schedule workload to execute on IDC servers through an input queue. Extensive evaluation experiments are performed to demonstrate that the proposed approach significantly reduces energy cost for IDCs, and guarantees a service delay bound for user requests.