When dd was a baby, there were two things that made her smell funky.
The one that most closely resembles what you're talking about was a sour, somewhat vinegar-y, but warmer smell, and that was when she had ear infections. She had recurring ear infections, eventually getting tubes in. About 90% of her ear infections were accompanied by that smell. And there was a direct and exact correlation btwn the smell, and when it was bacterial vs viral. I was an obsessive note-taker, and the infections that stank were helped by abx, and the ones that didn't, weren't helped by abx. The "smell test" was so reliable, that the drs knew if I said, "she has an ear infection, I can smell it," that I was right. It actually proved to be a useful diagnostic tool, because it let me know to get her to the dr right @ the start of each ear infection. With the nbr of ear infections she had, the drs were impressed w/ her total lack of hearing loss, and attribut it to early detection nearly every time. But I digress...
Also, once she was older, and started having cows milk, it made her head smell like rotten milk! That's how we discovered a dairy intolerance (not a lactose intolerance, btw) that eventually went away. But, until she was 5, -- boy, howdee! -- that stuff sure made her smell bad!
Also, you may try eliminating yeast. That's just an intuitive thought.