The emergence of cloud computing has established a trend towards building massive, energy-hungry, and geographically distributed data centers. Due to their enormous energy consumption, data centers are expected to have major impact on the electric grid by significantly increasing the load at locations where they are built. Dynamic energy pricing policies in the recently proposed smart grid technology can incentivize the cloud computing central controller to shift the computation load towards data centers located in regions with cheaper electricity. Moreover, data centers and cloud computing also provide opportunities to help the smart grid with respect to robustness and load balancing. To gain insights into these opportunities, we consider an interaction system of the smart grid and cloud computing. We provide the sequential game formulation of the interaction system, under two different dynamic pricing scenarios: the power-dependent pricing and the time-ahead pricing. The two players in the sequential games are the smart grid controller that sets the energy price signal and the cloud computing central controller that performs resource allocation among data centers. The objective of the smart grid controller is to maximize its own profit and perform load balancing among power buses, while the objective of the cloud computing controller is to maximize its own profit with respect to the location-dependent price signal. Based on the backward induction principle, we derive the optimal or near-optimal strategies for the two players in the sequential game using convex optimization and effective heuristic search techniques. Experimental results demonstrate the effectiveness of the proposed sequential game-based optimization framework on profit maximization and load balancing.