How can cos(x - pi/4) be rewritten as sin(x + pi/4)?

How? Because it's the same.

Recall that
sin(u) = cos(pi/2 - u)
So just plug in u = x + pi/4