Yes, you can. If you want to add coconut to a dessert stout, you should add it during the secondary fermentation and leave it for about two weeks.
It’s advisable to roast flaked coconuts until they are golden brown, as this would eliminate any oils that can affect the beer. The ideal amount is about two pounds for five gallons of beer.