In this paper, we investigate the utility maximization problem for a sensor network with energy replenishment. Each sensor node consumes energy in its battery to generate and deliver data to its destination via multi-hop communications. Although the battery can be replenished from renewable energy sources, the energy allocation should be carefully designed in order to maximize system performance, especially when the replenishment profile is unknown in advance. In this paper, we address the joint problem of energy allocation and routing to maximize the total system utility, without prior knowledge of the replenishment profile. We first characterize optimal throughput of a single node under general replenishment profile, and extend our idea to the multi-hop network case. After characterizing the optimal network utility with an upper bound, we develop a low-complexity online solution that achieves asymptotic optimality. Focusing on long-term system performance, we can greatly simplify computational complexity while maintaining high performance. We also show that our solution can be approximated by a distributed algorithm using standard optimization techniques. Through simulations with replenishment profile traces for solar and wind energy, we numerically evaluate our solution, which outperforms a state-of-the-art scheme that is developed based on the Lyapunov optimization technique.