How to define a nice name? Let $\mathbb{P}$ be a poset and $B,D$ be sets.
Let $p \in \mathbb{P}$ and  $\sigma$ be a $\mathbb{P}$-name such that $p \Vdash \sigma \in B$. Then there exist a nice name $\tau$ for an object in $B$ such that $p \Vdash \sigma = \tau.$
Also if  $\mu$  be a $\mathbb{P}$-name such that $p \Vdash \mu:D\to B$ Then there exist a nice name $\pi$ for a function from $D$ into $B$ such that $p \Vdash \mu = \pi.$
I am studying the book Kunen and I'm a little confused when defining a $\mathbb{P}$-name.
A suggestion of how to define a nice name. Thanks
 A: Although Neil already wrote what the idea behind nice names is, I decided to add some details, since almost each forcing textbook covers this topic in a different way.
Before giving all the formal details - repetition of what Neil wrote, in slightly different words, with applications to names for subsets of $\omega$:
a name $\sigma$ for a subset of $\omega$ in general consists of pairs of the form $(\check{n}, p)$. The requirement for $\sigma$ to be a nice name is that for every such $\check{n}$ the set of $p \in \mathbb{P}$ paired with this $\check{n}$ in $\sigma$ forms an antichain. 
To fulfill this requirement we will try to define a nice name $\sigma$ for a given name $\pi$ for a subset of $\omega$ by choosing for each name $\check{n}$ (i.e. each name for element of $\omega$) a (maximal) antichain of conditions forcing $n$ into $\pi_G$. That is, we try to define $\sigma$ so that the abovementioned $p$'s form a maximal antichain $A_n$ and force that $n \in \pi_G$. Then we will consider the set of conditions stronger then some element of $A_n$ and demosntrate it is dense, therefore an element of this set will be in the generic filter $G$, and as Neil wrote - generic filter has to intersect maximal antichains, so it will in particular contain a condition that is a righ-coordinate of some element of our nice name $\sigma$ which in effect will show that every subset of $\omega$ has a nice name. This will allow us to control the number of possible names of subsets of $\omega$, as long as we are able to control the sizes of the antichains in $\mathbb{P}$. 
Now, to the details:
Let $\sigma, \tau \in M^\mathbb{P}$. The name $\sigma$ is a nice name for a subset of $\tau$ if $dom(\sigma) \subseteq dom(\tau)$ and:
$$\forall \eta \in dom(\sigma) \: \forall p, q \in \mathbb{P} \: ((\eta, p) \in \sigma \: \wedge \: (\eta, q) \in \sigma \: \wedge \: p \neq q) \Rightarrow p \bot q,$$
which is the same thing as to say that for every $\eta \in dom(\sigma)$ the set of condition paired with $\eta$ in $\sigma$, i.e. the set $$\{p \in \mathbb{P}: (\eta, p) \in \sigma\}$$
is an antichain. 
Having a name $\tau$, and some name $\pi$ for its subset (i.e. such that $M[G] \models \pi_G \subseteq \tau_G$) we can always define a nice name $\sigma$ for the subset $\pi$ of $\tau$ (that's a first nice thing about the nice names): 
Lemma: For any $\tau, \pi \in M^\mathbb{P}$ there exists a nice name $\sigma \in M^\mathbb{P}$ for a subset of $\tau$ such that:
$$1_\mathbb{P} \Vdash \pi \subseteq \tau \Rightarrow \sigma = \pi.$$
The proof of the lemma gives an exact answer to your original question on how to define nice $\sigma$:
Proof: Let $M[G] \models \pi_G \subseteq \tau_G$. By the forcing theorem there is a condition $q \in G$ such that $$q \Vdash \pi \subseteq \tau.$$
Now we get into the defition of a nice name: for every $\eta \in dom(\tau)$ we define:
$$B_\eta := \{p \leq q: p \Vdash \eta \in \pi\}. (\ast)$$
By the Kuratowski-Zorn Lemma there is a maximal antichain $A_\eta \subseteq B_\eta$. 
Define the name $\sigma$ as:
$$\sigma = \{(\eta, p): \eta \in dom(\tau) \: \wedge \: p \in A_\eta\}.(\ast \ast)$$
Observe that $\sigma$ is a nice name for a subset of $\tau$ by definition (since $A_\eta$ was chosen to be an antichain), so the only thing we need to demonstrate is that $M[G] \models \sigma_G = \pi_G$.
The easier part is to show that $M[G] \models \sigma_G \subseteq \pi_G$. Indeed: suppose $M[G] \models \eta_G \in \sigma_G$. By definition it means that there is a condition $p \in G$ s.t. $M \models (\eta, p) \in \sigma$., i.e. $\eta \in dom(\tau)$ and $p \in A_\eta$, which by the definition of $A_\eta$ in particular means that $p \Vdash \eta \in \pi$ (since $A_\eta \subseteq B_\eta$). But then it just means that in $M[G]$ we have $\eta_G \in \pi_G$ - exactly what we wanted.
Now, the reverse inclusion is more interesting, and it is here that we will use the fact that $A_\eta$ is an antichain: we claim that $\pi_G \subseteq \sigma_G$. So assume $\eta_G \in \pi_G$. Now, instead of invoking the definition of $G$-values, we again refer to the forcing theorem: it means there is a condition $p_0 \in G$ such that $$p_0 \Vdash \eta \in \pi$$
(by the fact that $G$ is a filter $G$ (in particular - downwards directed), we can assume $p_0 \leq q$).
Now define the following set:
$$D = \{ p \in \mathbb{P}: p \: || \: p_0 \Rightarrow \exists r \in A_\eta \: p \leq r\}.$$
We first claim that $D$ is dense - then we will use the genericity of $G$ to conclude the proof with showing $\eta_G \in \sigma_G$.
To show that $D$ is dense, let $p_1 \in \mathbb{P}$ be any forcing condition. Suppose $p_1 \: || \: p_0$ (otherwise $p_1$ is already in $D$ itself) - this just means there is $p_2 \leq p_0, p_1$. Since $p_0 \Vdash \eta \in \pi$, we also know that $$p_2 \Vdash \eta \in \pi,$$ in other words that $$p_2 \in B_\eta.$$
Here comes the crucial step: since $A_\eta$ is a maximal antichain in $B_\eta$, there must be some $r \in A_\eta$ s.t. $p_2 \: || \: r$ (otherwise, $A_\eta \cup \{p_2\}$ would be an antichain striclty extending $A_\eta$), so there is a condition $p_3 \leq p_2, r$ that satisfies the defining condition of $D$, and obviously, by construction: $p_3 \leq p_1$, which proves the density claim.
So now, by genericity (and which is exactly what the last sentence of Neil's answer refers to), there has to be a condition $p \in G \cap D$, i.e. $p \in G$ such that $$p \bot p_0 \: \vee \: \exists r \in A_\eta \: p \leq r,$$
but since $p_0 \in G$, $p$ and $p_0$ have to be compatible, so $$\exists r \in A_\eta \: p \leq r.$$ But $G$ is a filter, so by the fact that $p \in G$, and $p \leq r$ we have $r \in G$ and $r \in A_\eta$, i.e. $(\eta, r) \in \sigma$ (definition of $A_\eta$!), that is:
$$\exists r \in G \: (\eta, r) \in \sigma,$$
which by the definition of $G$-values means that in $M[G]$ we have $\eta_G \in \sigma_G$, exactly as promised. $\square$
Comments about the proof:
$(\ast)$ You actually do not need to restrict to $p \leq q$ but it's neat this way.  - what is essential is that $B_\eta$ consists of these conditions that force $\eta$ to be an element of a given subset $\pi$ of $\tau$. 
$(\ast \ast)$ As you can see, the definition of the nice name $\sigma$ is relative not only to $\tau$, but also to $\pi$, because $A_\eta$ is chosen as a subset of $B_\eta$ that depends on $\pi$. An important thing here is that you can think of the nice name $\sigma$ as of a function $f_\sigma: \eta \mapsto A_\eta$, i.e. roughly speaking : mapping each candidate $\eta$ for a member of $\tau$ to a maximal antichain of conditions forcing that $\eta$ is an element of the subset $\pi$ of $\tau$ (I wrote roughly speaking, because these are all obviously just names of sets, canidates etc. but I assume it's clear).   
The above rather answers your question, but now -  why do we want to have nice names after all?
Well, the reason is as follows - and this is the essence of nice names: if we know a bound on possible sizes of antichains in $\mathbb{P}$, then we can also control how many antichains there are in $\mathbb{P}$, and  further - thanks to having nice names for subsets of $\tau$, i.e. for elements of $\mathcal{P}(\tau)$ - we are able to control the size of $\mathcal{P}(\tau_G)$. To be precise we have the following:
Fact: If $\mathbb{P}$ has c.c.c., and $\tau \in M^\mathbb{P}$, then:
$$M[G] \models |\mathcal{P}(\tau_G)| \leq (|\mathbb{P}|^{\aleph_0 \cdot |dom(\tau)|})^M.$$
Now, as an example: when you take $\mathbb{P}$ to be Cohen forcing $Fn(\kappa \times \omega, 2)$, assume $\kappa^{\aleph_0} = \kappa$ (or actually, that $cf(\kappa) > \aleph_0$), and $\tau_G$ to be $\omega$ (and then $\eta$'s are just names for natural numbers), what do you get?
A: A nice name can be defined as followed:
Definition IV.3.8 (In the 2013 edition of the Kunen) For $\tau \in V^{\mathbb{P}}$, a nice name for a subset of $\tau$ is a name of the form $\cup \{ \{\sigma \} \times A_{\sigma} | \sigma \in dom(\tau)\}$, where each $A_\sigma$ is an antichain in $\mathbb{P}$.
So a nice name for a subset of $\tau$ is one where you look at $\mathbb{P}$-names in the domain of $\tau$ (i.e. candidates for members of subsets of $\tau$), index antichains in $\mathbb{P}$ using these names, and then look at the set of ordered pairs you can make whose first coordinates are each $\sigma$, and second coordinates are the members of the antichain indeced by $\sigma$.
Essentially, you want to have names that interact nicely with the antichains in $\mathbb{P}$. The lemmas you mention show that you can find nice names that will do the job of normal $\mathbb{P}$-names, but give you a little more traction on what's going on with the antichains in $\mathbb{P}$ during a forcing construction. Remember any $\mathbb{P}$-generic over $\mathfrak{M}$ has to intersect a maximal antichain of $\mathbb{P}$. So, by using a nice name $\theta$ for a subset of $\tau$ (and where the antichain $A_{\sigma}$ is maximal, you're guaranteeing that for each $\sigma \in dom(\theta)$, $\sigma_G$ makes it into $\theta_G \subseteq \tau_G$, as the generic can't avoid including it.
