What length of finishing nail should I use?
Well, you want enough length that there is sufficient nail in the stud to hold the trim on. The drywall is 1/2" thick, so if your trim is 1/2" thick, that would only leave you 1/2" in the stud, which is not enough. So I would suggest 2" nails for what you are doing.