The aim of this paper is to show that, for a linear second-order hyperbolic equation discretized by the backward Euler scheme in time and continuous piecewise affine finite elements in space, the adaptation of the time steps can be combined with spatial mesh adaptivity in an optimal way. We derive a priori and a posteriori error estimates which admit, as much as it is possible, the decoupling of the errors committed in the temporal and spatial discretizations.