Out-of-plane ferroelectricity and robust magnetoelectricity in quasi-two-dimensional materials