Establishing the relationships is #1. Go to class. Participate. Go to office hours. give the professor a sense of who you are, so that he/she can write something beyond "KP Chicken got a B+ in my class."
As far as when you ask for the letters, and whether they need to be targeted, I would do this: go talk to several professors by the end of the term. Tell them of your plans (to go to school, but later), and say that you'll probably being asking for a letter at some point in the future. Most will say "OK, just get back in touch then." This way, when you get back in touch you can say "You may or may not remember me, but we talked about grad school in your office, and you said you'd write me a letter."
Then, when you get back in touch, make sure you provide them with tons of extra information, including exactly what you want to go to school for, and the personal details/qualities you'd like the letter to emphasize so that they can write a letter that sounds like they know/knew you very well, even if they've forgotten. You can even include a short outline of the points you'd like the letter to make. Trust me, most faculty will be happy that you've made the job easier.
Good luck.
PS I'm a professor myself and have written tons of letters over the years, in case you're wondering where this advice is coming from!