By using variational wave functions and quantum Monte Carlo techniques, we investigate the interplay between electron-electron and electron-phonon interactions in the two-dimensional HubbardHolstein model. Here, the ground-state phase diagram is triggered by several energy scales, i.e., the electron hopping t, the on-site electron-electron interaction U , the phonon energy ω0, and the electron-phonon coupling g. At half filling, the ground state is an antiferromagnetic insulator for U 2g 2 /ω0, while it is a charge-density-wave (or bi-polaronic) insulator for U 2g 2 /ω0. In addition to these phases, we find a superconducting phase that intrudes between them. For ω0/t = 1, superconductivity emerges when both U/t and 2g 2 /tω0 are small; then, by increasing the value of the phonon energy ω0, it extends along the transition line between antiferromagnetic and charge-density-wave insulators. Away from half filling, phase separation occurs when doping the charge-density-wave insulator, while a uniform (superconducting) ground state is found when doping the superconducting phase. In the analysis of finite-size effects, it is extremely important to average over twisted boundary conditions, especially in the weak-coupling limit and in the doped case.