Is an attorney permitted to ask questions like those in either paragraphs two and three?
Yes. That does not mean that they will be considered relevant or even appropriate, though.
Is the witness allowed to decline to answer such questions for reason of irrelevance, or other grounds?
Yes. In general, though, it would be safer for the witness to state an objection (be it on the basis of irrelevance, confrontational, asked & answered, as to form, etc.) and answer the question nonetheless, rather than simply refusing to answer it. By simply declining to answer a question regardless of the basis for refusal, the witness risks affording a crooked lawyer the opportunity to falsely generalize that the witness was uncooperative.
One exception to the idea of "object-and-then-answer" is where some privilege is the alleged basis for the objection, since the substance of the answer could be such that it amounts to waiving the privilege even where that privilege is legitimate.
The witness may also opt to answer the lawyer's irrelevant questions even without stating an objection. Some questions are so obviously irrelevant, dull, or stupid that a failure to raise an objection will be inconsequential. In such scenarios, raising objections can only lengthen the deposition transcript and make it harder to read.
For a real-life example of deposition with plenty of dull questions, take a look at the transcript (which I split in parts one, two and three) of the 4-hour deposition where I myself was the witness (you can download the case file, almost in its entirety, from this page).
You will notice that I did not raise objections during the deposition, the main reason being what I explained above: To avoid giving the opposing counsel an opportunity to falsely accuse me in court of being uncooperative during deposition.
Furthermore, addressing the crook's futile questions (1) projects transparency and helps on the witness's part, and (2) precludes a false & misleading impression as if the witness had something to hide. After all, wrongdoers are the ones most interested in eluding testimony in ways very similar to this other deposition.
The reason of being of objections is precisely that the law "is aware" that, as a matter of fact, lawyers indulge in all kinds of abusive questions when taking sworn testimony --be it in trial or at deposition-- of a witness.