From what I read, for the confirmation of residence, I need to go with the landlord to the local town hall. Is that right?
Yes you do.
how much does this document cost?
Nothing: it is free of charge.
what about the legal title to the apartment?
The person who is renting the apartment to you needs to bring proof that he has a legal title to the property (e.g. the notarial deed from when he bought the flat) and you need to bring a copy of your rental agreement.
The problem that you may well find is that your landlord is unwilling to register you in his flat (that will be because he isn't paying any tax on the money which you are giving him).