When are we (not) allowed to replace $x$ by $ix$? It seems to be quite a common manipulation to replace $x$ by $ix$.
Every time I see it's being done in a textbook, I blindly trust the author without really understanding when are we allowed to do so in each particular case and when not. 
If you know any examples of false usage, I'd be happy to learn from them.
What one generally needs to keep in mind while replacing $x$ by $ix$?
For example, if we replace $x$ by $ix$ in the following:
$$ x \coth(x)=\sum_{n=0}^\infty \frac{2^{2n}}{(2n)!}B_{2n}x^{2n} $$
what should be the correct justification for the replacement?


*

*Because $ix$ is just a rotation of $x$, so $|x|=|ix|$, therefore if the series converges for $x$ then so it does for $ix$.

*Because both LHS and RHS are defined for a complex argument.


Both/one/none of them? What could go wrong?
 A: Yes, in general, you need to be careful when replacing $x$ by $ix$. For instance, below is a false usage:
$$\int_{-\infty}^{\infty} \exp(-x^2) dx = \sqrt{\pi}$$
Replacing $x$ by $ix$, we get that
$$\int_{-\infty}^{\infty} \exp(x^2) dx = \dfrac{\sqrt{\pi}}{i}$$
Similarly, for $x \in \mathbb{R}$, $\vert \exp(ix) \vert = 1$. However, we cannot replace $x$ by $ix$ and conclude that $\vert \exp(-x) \vert = 1$.
The main thing is, if we know a result is true for real $x$, we need to check if the result can be holomorphically extended into the complex domain.
A: Consider your example
$$
x \coth(x)=\sum_{n=0}^\infty \frac{2^{2n}}{(2n)!}B_{2n}x^{2n}
$$
Both sides are analytic functions of $x$.  Since they agree on a set with a limit point (an interval of the real line), they also agree for complex numbers $x$.  That is more than merely for complex numbers of the form $ix$.
A: Your example of "false usage" is not actually an example, since $\cos(ix)+i\sin(ix)$ does equal $e^{-x}$. Your rules for replacement are basically correct, with one caveat: rule 1 should read instead
1.Because $|x|=|ix|$, if the series converges absolutely for $x$ then it also does for $ix$.
In general a series can converge for $x$ but not $ix$. Consider for example the series
$$\sum\limits_{n=1}^\infty \frac{x^n}{n}$$
which converges for $x=-i$ but not for $ix=1$. 
A: Your 'wrong' example is right! Both sides are analytic functions which agree everywhere. (See e.g. WolframAlpha.)
Neither of your rules in sufficient in general; c.f. $|x|^2=x^2$.
The most common reason why this works is that if $f(z),g(z)$ defined for all $z$ in some open connected set $U\subset\mathbb C$ (by some method like power series) are analytic (complex differentiable/equal to their power series) then
$$f(z)=g(z)\quad\text{ for } z\in S \implies f(z)=g(z)\text{ for } z\in U$$
provided $S\subset U$ is 'big enough', like a line $\mathbb R\subset \mathbb C$. (It needs a limit point.)
So why doesn't $|x|^2=x^2$ work? Because $|z|^2=z\times\bar z$ is not analytic; it involves $\bar z$.
