Energy harvesting (EH) technology enables wireless nodes to operate in a self-powered fashion; however, the stochastic nature of the harvesting process and the limited amount of harvested energy require efficient management of the available resources. In this paper, an EH transmitter communicating over a fading channel is studied considering jointly the energy costs of transmission and processing. In particular, under the assumption of known energy and data arrival profiles and fading states, optimal transmission policies are studied, so that, the remaining energy in the battery of the transmitter is maximized by a given deadline while all the arriving data packets are delivered to the receiver. A 'directional glue pouring' interpretation is provided for the algorithm that computes the optimal offline transmission policy. The relation of this problem with the transmission completion time minimization problem is also discussed. Finally, a heuristic algorithm for online optimization, which performs close to the optimal offline transmission policy, is proposed.