In my book, UFD is defined as - if every nonzero nonunit element can be uniquely written as factors of irreducible elements. But wiki says non-zero element can be written as product of factors of irredicible elements and unit (https://en.wikipedia.org/wiki/Unique_factorization_domain). Pls enlighten on how these 2 are equivalent.
Your book should really add the phrase "up to units" as part of the definition. Otherwise the following is technically not unique $6=2\cdot 3 = (-2)\cdot (-3) $ but $\mathbb Z$ is the mother of all UFDs.
Another way I've seen this dealt with is the notion of associates. Two non-zero elements $a,b$ in a ring are said to be associate if there is a unit $u$ such that $a=bu$. My favourite statement of unique factorization domain is a domain such that every non-zero element is expressible as a product of irreducible elements (which have to be non-units) and any two such expressions $a_1\cdots a_n$ = $b_1\cdots b_m$ means that $n=m$ and there is some reordering so that $a_i$ and $b_i$ are associates.