I remember watching a children's animated movie several years ago, but I do not remember much. I do remember it involved a man who got trapped in a fantasy world somehow, dragons that needed to eat certain rocks in order to breathe fire, and the man defeats the villain by rapidly yelling the names of branches of science that end in "-ology."
This is The Flight of the Dragons (1982), a Rankin-Bass cartoon.
Per Wikipedia (with emphasis added on the points relevant to the specific plot elements mentioned in the question):
In an age of medieval fantasy populated by fantastic creatures, the Green Wizard Carolinus, who presides over nature, notices that magic is fading from the world as humanity embraces logic and science instead. Summoning his three magical brothers, he proposes combining their powers to create a "last realm of magic" hidden from the rest of the world. The Blue Wizard Solarius, who commands the heavens and seas, and the Yellow Wizard Lo Tae Zhao, whose realm is light and air, agree to the proposal. However, the Red Wizard Ommadon, master of black magic and the forces of evil, resolves instead to infect mankind with fear and greed, causing humans to use their science to destroy themselves.
Since the wizards are forbidden to fight among themselves, Carolinus proposes sending a group of heroes on a quest to steal Ommadon's crown, which is the source of his power. The party includes the knight Sir Orrin Neville-Smythe and Carolinus' young dragon companion Gorbash. Solarius gives them an enchanted shield which can deflect dark magic, and Lo Tae Zhao contributes a magic flute which lulls dragons to sleep. Requiring a leader, Carolinus consults the magical force of Antiquity, which directs him to look 1,000 years into the future to find a man of science descended from a legendary hero. In late 20th century Boston Carolinus locates Peter Dickinson, a former scientist turned board game designer who is obsessed with dragons. Carolinus brings Peter back through time and enlists him in the quest, and Peter becomes enamored of Carolinus' ward, Princess Melisande. Ommadon sends his dragon Bryagh to capture Peter, and an accident with one of Carolinus' spells while rescuing him causes Peter to merge with Gorbash, Peter's mind taking over the dragon's body.
Knowing nothing about being a dragon, Peter is mentored by Carolinus' elder dragon companion, Smrgol. The dichotomy of magic and science is explored when Smrgol teaches Peter how dragons fly and breathe fire, abilities which Peter is able to explain with scientific principles. As the quest progresses, the heroes survive an attack by the monstrous Sand Murks and are joined by the talking wolf Aragh, the archer Danielle, and the elf Giles. As the party nears Ommadon's realm, Danielle and Sir Orrin are captured by an ogre. Peter is nearly killed attempting to rescue them but is saved by Smrgol, who defeats the ogre at the cost of his own life. In the Red Wizard's realm the party faces the Worm of Sligoff, which Peter destroys by igniting the sulfuric acid it excretes. Ommadon casts a spell to induce hopelessness in the group, which Peter repels using Solarius' shield. Ommadon next sends numerous dragons to kill the heroes, but Giles plays Lo Tae Zhao's enchanted flute, lulling them and Peter to sleep. Bryagh remains awake and kills Giles, Aragh, and Danielle. Sir Orrin slays Bryagh, but dies from his wounds.
When Ommadon appears on the battlefield, Peter manages to separate himself from Gorbash by recalling the principle of impenetrability. He is able to defeat Ommadon by countering the wizard's declarations of magic with explanations of science and logic, and denying the existence of magic. This destroys Ommadon, restores the other heroes to life, and allows the magical realm to take shape. Peter, having denied all magic, is separated forever from this realm, but not before awakening Melisande with a kiss and leaving her Ommadon's crown. Having fallen in love with Peter, Melisande begs Carolinus to allow her to join him. Back in 20th century Boston, Peter is selling the magic flute and shield to a pawnbroker when Melisande enters the shop carrying the crown, and the two embrace.