Formation of stellar shells and X-ray coronae around elliptical galaxies