Yes, X1 capacitors can replace X2 capacitors and Y1 capacitors can replace Y2 capacitors. X1/Y1 have a higher safety rating than X2/Y2. Ceramic X and Y parts will work fine as replacements for common film and/or paper X and Y capacitors.
Also, Y capacitors can replace X capacitors but not the reverse. The difference is that Y capacitors are tested to fail open instead of shorted. X capacitors are permitted to short because being connected line-to-line, they present no danger. But typically Y capacitors are much lower value than X capacitors.