Several years ago i asked this same question to a Mujtahid in Najaf. The first thing he replied was that this is an easy thing to say, but in reality it is not an easy task to accomplish. He continued to say that we needed to pray to Allah and ask Him to open our container and expand our capacity, so that we can receive the knowledge pertaining to Imam Mahdi (pbuh). Being among those who are close to the Imam means having a very high level of knowledge and piety, so we must be prepared mentally and spiritually to understand, comprehend and accept this knowledge.
He proceeded to say that one of the ways that we can gain proximity to the Imam is to fulfill all of our obligations (wajibat) that Allah has asked from us. Next is to stay away from all of the things Allah has forbidden us from doing (muharramat). This reminds me of the first thing he told me when he said that it sounded easy but in reality, was not an easy task at all. Last of all he told me that to become close to the Imam we should be careful of how we treat others. We should always treat others well, with respect and give them their due rights. We should never be oppressors and mistreat people.
The second question you asked, you just make the intention to gift the reward of the good action to the particular person you would like to dedicate it to.