You say “recently,” so I am wondering how new this is. If it is super new, I would take him to a physician to ensure that this is not being caused by an underlying medical condition or new drug interaction on top of his preexisting dementia. It could also be a urinary tract infection.
As long as it is not something like that, go with his flow. Sounds to me like he could have Dementia with Lewy Bodies because of his hallucinations. Does he have any Parkinson’s-like symptoms?
I’m glad he’s happy about his conversations with his imaginary companion. that’s really the best case scenario. You have an interesting opportunity here to ask him about his companion and learn a little more. This could be an enjoyable, although a little strange, experience for both of you.
This new event, where he is upset and yelling, makes me think that there could be another medical issue going on. I recommend getting a doctor to see him today or very soon so that you can rule out any other underlying issues.