Is there any story about how Lord Dattatreya acquired the knowledge of Yoga?
As I discuss in this answer, Dattatreya was the son of the sage Atri, one of the mind-born sons of Brahma, and his wife Anasuya, who had received a boon that Brahma, Vishnu, and Shiva would be born as her sons. And sure enough, Brahma incarnated as her son Chandra the moon god, Vishnu incarnated as Datta AKA Dattatreya, and Shiva incarnated as the short-tempered sage Durvasa.
Now as to your question concerning how Dattatreya acquired his knowledge of Yoga, the ancient king Yadu, founder of the Yadava dynasty that Krishna was a member of, once asked Dattatreya that very question, as described in the Srimad Bhagavatam:
O brāhmaṇa, I see that you are not engaged in any practical religious activity, and yet you have acquired a most expert understanding of all things and all people within this world. Kindly tell me, sir, how did you acquire this extraordinary intelligence, and why are you traveling freely throughout the world behaving as if you were a child? Generally human beings work hard to cultivate religiosity, economic development, sense gratification and also knowledge of the soul, and their usual motive is to increase the duration of their lives, acquire fame and enjoy material opulence. You, however, although capable, learned, expert, handsome and most eloquent, are not engaged in doing anything, nor do you desire anything; rather, you appear stupefied and maddened as if you were a ghostly creature. Although all people within the material world are burning in the great forest fire of lust and greed, you remain free and are not burned by that fire. You are just like an elephant who takes shelter from a forest fire by standing within the water of the Ganges River. O brāhmaṇa, we see that you are devoid of any contact with material enjoyment and that you are traveling alone, without any companions or family members. Therefore, because we are sincerely inquiring from you, please tell us the cause of the great ecstasy that you are feeling within yourself.
Dattatreya responded that he did not acquire his knowledge from any actual Guru, but rather he achieved an enlightened state by observing various people, animals, and elements of nature, and taking their lessons to heart:
My dear King, with my intelligence I have taken shelter of many spiritual masters. Having gained transcendental understanding from them, I now wander about the earth in a liberated condition. Please listen as I describe them to you. O King, I have taken shelter of twenty-four gurus, who are the following: the earth, air, sky, water, fire, moon, sun, pigeon and python; the sea, moth, honeybee, elephant and honey thief; the deer, the fish, the prostitute Piṅgalā, the kurara bird and the child; and the young girl, arrow maker, serpent, spider and wasp. My dear King, by studying their activities I have learned the science of the self.
You can read the lessons he learned from each of his 24 "Gurus" in this chapter, this chapter, and this chapter of the Srimad Bhagavatam. It would make the answer too long to quote all 24 lessons, but for instance here is what he learned from the sky:
A thoughtful sage, even while living within a material body, should understand himself to be pure spirit soul. Similarly, one should see that the spirit soul enters within all forms of life, both moving and nonmoving, and that the individual souls are thus all-pervading. The sage should further observe that the Supreme Personality of Godhead, as the Supersoul, is simultaneously present within all things. Both the individual soul and the Supersoul can be understood by comparing them to the nature of the sky: although the sky extends everywhere and everything rests within the sky, the sky does not mix with anything, nor can it be divided by anything. Although the mighty wind blows clouds and storms across the sky, the sky is never implicated or affected by these activities. Similarly, the spirit soul is not actually changed or affected by contact with the material nature. Although the living entity enters within a body made of earth, water and fire, and although he is impelled by the three modes of nature created by eternal time, his eternal spiritual nature is never actually affected.
Note that the three chapters I linked to are part of the Uddhava Gita, a Bhagavad Gita-like religious discourse between Krishna and his relative Uddhava which I discuss here.
EDIT: Here's a picture summarizing the 24 lessons: