In this work, we propose an optimal privacy-bydesign strategy using an energy storage system (ESS) that is capable of shaping the user demand to follow a time-varying target profile. In addition, we consider the ESS usage cost due to its energy losses and capacity degradation. We measure the privacy leakage in terms of the Bayesian risk. The proposed strategy is computed by solving a multi-objective optimization problem using the Markov decision process framework. With numerical simulations using real household consumption data and a lithium-ion battery model, we study the trade-off between the achievable Bayesian risk, the variations in the user demand from the target profile and the energy storage cost. The results show that by trading-off some privacy, the variations in the user demand can be reduced while improving the battery lifetime. Index Terms-Smart meter privacy, energy flow management, Markov decision process, dynamic programming, Bayesian hypothesis testing, user demand shaping.