tensor product of non free modules which is free

Here's an example. Let $A$ and $B$ be two nonzero commutative rings and $R=A\times B$. We can consider $A$ and $B$ as $R$-modules, and they satisfy $A\otimes B\cong 0$ and $A\oplus B\cong R$. Taking $S=A\oplus R$ and $T=B\oplus R$, we thus see that $$S\otimes T\cong A\oplus B\oplus R\cong R^2$$ is free but $S$ and $T$ are not free. More generally, $(A^i\oplus B^j)\otimes(A^k\oplus B^l)\cong A^{ik}\oplus B^{jl}$ is free iff $ik=jl$, but the factors are not free unless $i=j$ and $k=l$.


In general if we have an invertible $R$-module $M$, then the natural map $M \otimes_R M^\vee \to R$ is an isomorphism, where $M^\vee = \operatorname{Hom}_R(M,R)$ is its dual module. If $R$ is a Dedekind domain then every fractional ideal is an invertible $R$-module, and if $R$ has nontrivial class group, then any nonprincipal fractional ideal fulfills your requirements.

For an explicit example, take $R = \mathbb{Z}[\sqrt{-5}]$ and $I = (2, 1 + \sqrt{-5})$. Then $I \otimes_R I^\vee \cong R$, but since $I$ is nonprincipal, then it is not free. Since the class group of $\mathbb{Z}[\sqrt{-5}]$ has order $2$, then it turns out that $I^\vee \cong I$, so it is also not free.

For more examples and results on invertible modules, see $\S11.3$ of Eisenbud's commutative algebra book.