This is basically a re-writing of the answer of Luc Guyot. I would like to present not only the calculation of the rank, but also the algorithm for calculating a basis.
Let $K$ be a number field, and let $\lambda_1, \cdots, \lambda_n$ be elements in $K^\times$. Let $f$ be the morphism $\mathbb{Z}^n \rightarrow K^\times$ sending $(z_1, \cdots, z_n)$ to $\lambda_1^{z_1} \cdots \lambda_n^{z_n}$. We want to establish an algorithm for calculating a basis of the kernel $\ker(f)$.
Let $\mathcal{O}$ be the ring of integers of $K$. Write $\mathcal{I}$ for the group of fractional ideals, which is a free abelian group generated by prime ideals of $\mathcal{O}$.
Denote by $\iota$ the canonical map $K^\times \rightarrow \mathcal{I}$ sending $\lambda$ to the principle ideal $\lambda\mathcal{O}$. The map $f$ induces a map $\tilde{f}: \ker(\iota \circ f) \rightarrow \ker(\iota) = \mathcal{O}^\times$, and it is clear that $\ker(f) = \ker(\tilde{f})$.
The algorithm then goes in two steps:
Step 1. Compute a basis of $\ker(\iota \circ f)$, i.e. an isomorphism $\tau:\mathbb{Z}^d \rightarrow \ker(\iota \circ f)$.
This is done by decomposing every $\lambda_i$ into prime ideals, hence reducing to a morphism between $\mathbb{Z}^n$ and $\mathbb{Z}^m$, where $m$ is the number of prime ideals involved.
Step 2. Compute a basis of the kernel of the composition $\tilde{f} \circ \tau:\mathbb{Z}^d \rightarrow \mathcal{O}^\times$, so that $\ker(\tilde{f})$ can be determined via $\ker(\tilde{f}) = \tau(\ker(\tilde{f} \circ \tau))$.
Similarly, this only requires a basis of $\mathcal{O}^\times$. Note that the group $\mathcal{O}^\times$ also has a torsion part, which should be taken into account.
If we assume that the field extension $K/\mathbb{Q}$ is "small", then there are efficient algorithms for both the ideal decomposition and the unit group computation.
In the case of the original problem, one should take $K$ to be the splitting field of the polynomial $g(x)$, which (when $g(x)$ is irreducible) typically has degree $n!$ over $\mathbb{Q}$, hence not quite "small". But it should work well in some special cases (e.g. $g(x)$ only have roots in $\mathbb{Q}$).