Formation and dynamics of shells around elliptical galaxies