EDIT: At the bottom, I'll explain how, if you have a ring $R$ and a subset $A$ of $R$, how you can construct a theory such that any model of that theory contains a copy of $R$ such that the copies of elements of $A$ are units.

First, let me comment on a couple issues with the approach you're taking. Then I'll try to resolve these issues by answering your question, but since I'm not 100% sure what your question is I'll give two answers.

Some technical issues: The formula $\exists x, x = x$ doesn't say anything, it just says "there's something which is equal to itself," which essentially just says "there is something." Furthermore, this formula is only well-formed when $x$, is a variable, it doesn't make sense to say it when you're picking $x$ to be some element of your ring, it would be like saying $\exists 4, 4 = 4$. Also, this formula doesn't depend on $x$ the way I think you expect it to. The formulas $\exists x, x = x$ and $\exists y, y = y$ are essentially the same, much like how $\int f(x) dx$ and $\int f(y) dy$ are the same.

I understand what you're trying to do with your theory $T_x$ (or $T_f$ in the comments), it's supposed to be a theory such that any model has an inverse for all the $x \in A \setminus${$0$}. The theory you've constructed won't work for various reasons, some of which can be fixed and some can't. One problem is there's nothing to ensure that a model of $T_x$ has a copy of your original $M$, but this can be fixed. Another problem is that there's no guarantee that $T_x$ has a model at all. Or rather, there is a guarantee, and that guarantee comes from the already known fact in commutative ring theory that localizations exists, but model theory is not doing any work for you here. Similarly, model theory does nothing to guarantee that any resulting model will satisfy the desired universal property.

Now here's how we might try to salvage your approach, and use model theory to "construct" the localization. I won't go into full detail here since I'm not sure this is what you want to know, but if you want more details just ask and I'll edit my post accordingly (edit: I've added some details at the end). The vague outline is this: Forget the universal property for now. Pick an appropriate signature, and theory in this signature, such that a model of this theory would give you the desired object - in this case a commutative ring $N$ into which $M$ embeds such that the image of $A$ under this embedding is contained in the set of units of $N$. Then, show that every finite subset of this theory has a model, which will essentially amount to showing that you can produce a localization (minus the universal property) for any finite subset of $A$. At this point, the Compactness Theorem will give a model of your entire theory, and you'll have your $N$ (and implicitly, your embedding).

There's a couple problems here. First, how would you tackle the stage where you need to be able to show that you can produce a localization (minus the univ. prop.) for finite subsets of $A$? I would use one of the standard ring-theoretic proofs of the existence of the localization. But these proofs are sufficiently general that it's just as easy to apply them to the whole of $A$ as it is to apply them to any finite subset of $A$. In other words, if you're going to have to use a ring-theoretic proof of the existence of localizations at some point in a model-theoretic construction of the localization, why do any of the model theory in the first place and apply your ring-theoretic proof directly to $A$?

More crucially, we have a problem with the universal property. There's no way to express the universal property in first-order language *in such a way* that the result of applying the Compactness Theorem has the desired universal property. If we are working in a much richer structure (e.g. a model of ZFC) where we can talk about rings and the elements of rings both as objects in our universe, then we can express, in a first-order way, that $N$ is the localization $A^{-1}M$, including saying everything we need to about the universal property. This is just an instance of the fact that most math can be expressed in ZFC. But if we're trying to do something like in the previous paragraph, where we use model theory, especially Compactness, to produce a localization, then we want to work in the language of rings. In this case, our universe has to pretty much be just a ring, thus its elements will be objects of a ring, and so we don't have as objects all rings, and all morphisms between rings, etc, i.e. we don't have enough expressive power to talk about the universal property. And since we can't express the universal property, applying Compactness has no way of guaranteeing us that the resulting object satisfies the universal property.

So to summarize, if you're trying to construct the localization using model theory, you can get all of it except the universal property, but even then, in order to get it you have to make heavy use of ring theory to the point that the model theory isn't doing any of the work for you.

If you merely want to express or axiomatize what it means for something to be the localization of something else, it depends on how rich a structure you want to work in. If you want to work in ZFC, of course you can express pretty much everything. If you want to work in the language of rings, you can express everything except the universal property (and again, I can give details of this if you'd like).

EDIT: Consider the following signature:

$\sigma = (0, 1, +, \times, c_r (r\in R))$

Here, $0, 1$ and each $c_r$ are constant symbols, and the other two symbols are binary function symbols. Let $\mathrm{diag}^+(R, 0, 1, +, \times)$, the so-called **positive diagram of $R$**, consist of all true atomic formulas in the structure $(R, 0, 1, +, \times, r (r\in R))$ regarded as a $\sigma$-structure. Now consider the $\sigma$ theory which is the union of the following theories:

- $\mathrm{diag}^+(R, \dots , \times)$
- $\{c_r \neq c_s\ |\ r, s\in R,\ r\neq s\}$
- $\{$the commutative ring axioms$\}$
- $\{\exists x (x \times c_a = 1)\ |\ a \in A\}$

The first two will guarantee that we have a copy of $R$ sitting inside our resulting structure, the third guarantees that this structure is a commutative ring, and the last guarantees that everything in $A$ has a unit.