Nowadays, modern data centers are seeking for importing renewable energy together with conventional energy in order to be more environment-friendly and to reduce operation expenditures. Meanwhile, considering the fact that electricity prices and renewable energy generations are diverse in time and geography, a task scheduling strategy should be designed to ensure the efficient and economic operations of data centers. In this paper, an optimal task placement strategy is presented for geo-distributed data centers powered by mixed renewable and conventional energies with dynamic voltage and frequency scaling technique. We aim at minimizing the total electricity cost and making full use of the renewable energy so as to construct green and economic data centers. The optimal task placement problem is formulated as a mixed integer nonlinear problem (MINLP), in which the quality-of-service constraint is restricted by an M/G/1 queuing model. To tackle the complexity of the MINLP, we first transform it into a tractable form, and then develop an optimal sever activation configuration and task placement algorithm to solve it. The proposed algorithm can obtain the global optimal solution of the electricity minimization problem and meanwhile dramatically reduce the complexity of the problem solving. Finally, evaluations based on real-world traces exhibit impacts of different system parameters on the electricity cost and sever activation configurations, which prove the superiority of our proposed algorithm and provide us some illuminations on how to build cost-effective and eco-friendly data centers.