Reconfigurable intelligent surfaces (RISs) have attracted enormous interest thanks to their ability to overcome line-of-sight blockages in mmWave systems, enabling in turn accurate localization with minimal infrastructure. Less investigated are however the benefits of exploiting RIS with suitably designed beamforming strategies for optimized localization and synchronization performance. In this paper, a novel low-complexity method for joint localization and synchronization based on an optimized design of the base station (BS) active precoding and RIS passive phase profiles is proposed, for the challenging case of a single-antenna receiver. The theoretical position error bound is first derived and used as metric to jointly optimize the BS-RIS beamforming, assuming a priori knowledge of the user position. By exploiting the low-dimensional structure of the solution, a novel codebook-based robust design strategy with optimized beam power allocation is then proposed, which provides low-complexity while taking into account the uncertainty on the user position. Finally, a reduced-complexity maximum-likelihood based estimation procedure is devised to jointly recover the user position and the synchronization offset. Extensive numerical analysis shows that the proposed joint BS-RIS beamforming scheme provides enhanced localization and synchronization performance compared to existing solutions, with the proposed estimator attaining the theoretical bounds even at low signal-to-noise-ratio and in the presence of additional uncontrollable multipath propagation.