I once made a coffee stout and learned a very important thing,when it comes to flavoring beers/stouts, a little goes a long way, especially as time progresses and the flavors concentrate. I used 4 oz of espresso beans cold brewed in 3 or so cups of water, added it to a 5 gallon batch at bottling, tasted it, panicked is wasn't coffee enough, gave the coffee grounds another quick wash, added it, and thought maybe I nailed it. Yup, I nailed it alright, three weeks later the coffee flavor became so strong, I just couldn't stand to drink it. And the flavor strength continued to increase even more. I still love my morning coffee, but any beer that even hints to coffee, I just can't drink it.
As to your question about when to add coffee flavor, the jury is still out, but adding coffee beans to hot wort can possibly bring bitter oils out has been discussed, and adding at every different stage of brewing/racking. I will suggest, think about your level of hop bitterness before you add your coffee, as the added bitterness from the coffee may take your stout too far/bitter.