How to write a grammar for this language?
Your language is regular, and so one way to construct a context-free grammar for it is to first consider a finite state automaton, and then convert it to a grammar. Of course, this methodology only works for regular languages, and is not necessarily the easiest way in every case.