As long as you restrict yourself to sentences (so all of propositional logic, but also formulas in quantificational logic without any free variables), then these substitutions are indeed perfectly logically valid, and several texts prove a kind of 'Substitution Theorem' or 'Replacement Theorem' to this effect.
Moreover, there are formal proof systems that allow you to do this kind of thing. Some proof systems have a set of predefined logical equivalences (such as Double Negation, DeMorgan, Commutation, Association, Distribution, etc.) that can be used as inferences in a proof (see for example Copi's formal proof systems) and I know I have seen proof systems where any earlier proven equivalence can be used as a 'substitution' inference in other proofs.
When it comes to formulas in general (where you can have free variables) you need to be a little more careful, as you already realized (although I cannot quite follow your example ...). However, we can still a few things as far as equivalences and substitutions go.
First of all, as long as no variables are changed, we can easily extend the propositional logic equivalences to formulas. Thus, we can say that $Happy(x) \Leftrightarrow \neg \neg Happy(x)$, and since we can likewise extend the 'Substitution Theorem' to formulas, we can therefore infer $\forall x \ \neg \neg Happy(x)$ from $\forall x \ Happy(x)$.
When variables are changed, though, things get more tricky. In fact, it may seem that $Happy(x)$ is logically equivalent to $Happy(y)$, but clearly you cannot infer $\forall x \ Happy(y)$ from $\forall x \ Happy(x)$. Fortunately, it turns out that $Happy(x)$ not logically equivalent to $Happy(y)$ anyway, as we define the logical equivalence of formulas in terms of variable assignments (functions that map variables to objects in the domain) and as such I can map $x$ to a different object than $y$, and thereby demonstrate their non-equivalence.
Nevertheless, there still are equivalences that involve changing variables: $\forall x \ Happy(x)$ is equivalent to $\forall y \ Happy(y)$. Indeed, there is a general 'Replacing Bound variables' equivalence principle:
Replacing Bound variables
Where $\varphi(x)$ and $\varphi(y)$ are any FOL formulas, and where $\varphi(x)$ would be the result of replacing all free variables of $y$ in $\varphi(y)$, and where $\varphi(y)$ would be the result of replacing all free variables of $x$ in $\varphi(x)$:
$\forall x \ \varphi(x) \Leftrightarrow \forall y \ \varphi(y)$
$\exists x \ \varphi(x) \Leftrightarrow \exists y \ \varphi(y)$
In sum, then, as long as you have a good definition of logical equivalence of formulas, then there is indeed a general Substitution Principle of exactly the kind you suggest, and you could even make that into a formal inference rule.