We analyze the ground-state properties of strongly-correlated electrons coupled with phonons by means of a generalized Gutzwiller wavefunction which includes phononic degrees of freedom. We study in detail the paramagnetic half-filled Hubbard-Holstein model, where the electron-electron interaction can lead to a Mott transition, and the electron-phonon coupling to a bipolaronic transition. We critically discuss the quality of the proposed wavefunction in describing the various transitions and crossovers that occur as a function of the parameters. Previous variational attempts are recovered as particular choices of the wavefunction, while keeping all the variational freedom allows to access regions of the phase diagram otherwise inaccessible within previous variational approaches.