In this paper, we propose a battery-aided demand response strategy to minimize the energy expenditure incurred by grid-tied systems such as domestic and industrial loads. Unlike existing algorithms in the literature, our proposed strategy takes into account the non-linear behavior of the rechargeable battery. In addition, continuous-time block tariffing is adopted as a pricing strategy that generalizes current schemes such as time-of-use and consumption-based block pricing. To find the optimal demand response strategy, we formulate a nonconvex optimization problem, for which we obtain an approximate solution by introducing linearization and discretization in time. To gain further insight, we derive an analytical solution by introducing some simplifying approximations that allow us to use calculus of variations to obtain closed-form analytical results for the optimal charging and discharging schedules. Through simulations, we show that the strategy based on calculus of variations is able to achieve better performance and incur smaller computational costs than the solution based on discretisation in time. Finally, we discuss how the energy expenditure is related to pricing parameters, and specifications of the battery such as size and Peukert exponent.