Asking for rec letters: Ask at least a month in advance. Two-Three months ahead is probably best, and then when the deadline is a month away, you can begin to remind them. Be professional even if you know the professor well. If you got into undergrad or grad school then you should have some experience with this. Here are some links if you want some reminders on proper etiquette.
Sometimes you will be asked to write the letter for yourself. This usually occurs if you are working with someone who is super busy or if you don't know the professor very well. This can be a very daunting task, but luckily there are many helpful sources on the internet. Writing a rec letter for yourself takes requires you to balance strong support for yourself while not coming off to arrogant. Also, since this rec letter is to be from the professor, you don't want to presume that the professor thinks you are a rockstar. A little modesty is probably key, and you can leave it up to the professor to spice it up if they feel you deserve it. The details of the letter should focus on some concrete evidence from your interactions with this person. You will need to keep in mind the context in which you know this person and what actions/character/contributions they can actually discuss about you. Following up on this, you should also indicate in the beginning of the letter how this individual knows you. Here are some helpful links:
Prof. Wikswo class: "Write a ~one-page letter of recommendation for yourself, in my voice and from my perspective (as best as you can estimate), as if I were recommending you for either graduate school, medical school, or a job in academia or industry, or a graduate fellowship. Begin with the context in which I have known you. Describe what you accomplished in this context. Have you grown intellectually or personally, and if so, how? Explicitly cover your strengths and weaknesses, provide detailed comments regarding your memorable contributions to the class. Close by stating why I think you are (or are not) a good match to the proposed activity."