How much time passes between Daenerys locking up her dragons, and Tyrion freeing them? Weeks? Months? Years?
Game of Thrones
The timeline in Game of Thrones is deliberately vague with events in the same episode in different areas sometimes being months apart. Whilst the unofficial timeline is one season = one year this doesn't really hold up when you look at some events between seasons. However, seeing as this is the best we really have I shall answer from that perspective.
Daenerys first chains up Viserion and Rhaegal in Season 4 Episode 10, "The Children", and Tyrion releases them in Season 6 Episode 2, "Home". They then break out of the catacombs in Season 6 Episode 9, "Battle of the Bastards". The links are to YouTube clips showing these events happening.
Looking at this it would appear that both dragons were locked up for somewhere in between one to two years. Though I'd imagine it is more likely somewhere between the lower half of that estimate.
A Song of Ice and Fire
TL;DR: We can't know for sure but estimates put it around 6 months.
Before we get into an answer based on the books there are two important things you need to remember. Firstly, sizes and times of locations and events in the books have been left vague on purpose as George does not want people obsessing over these things; that isn't why he wrote the books.
[How big is Westeros? Is it the size of Europe, or even larger?]
I have deliberately tried to be vague about such things, so I don't have obsessive fans with rulers measuring distances on the map and telling me Ned couldn't get from X to Y in the time I say he did.
However, if you really must know, you can figure out the distances for yourself. The Wall is a hundred leagues long. A league is three miles. Go from there.
But if you turn up any mistakes in travel times by using that measure, let it be your secret.
Then when looking into the writing itself George believes in using the "unreliable narrator". In the same way as when you look back in history events might not be described exactly the same as what happens, the same happens in the books. The chapters are told from the point of view of characters and so events may be mis-remembered or interpreted differently between characters and at different times.
There was a long discussion about mistakes and inconsistencies. He used the eyes changing color example, and also mentioned receiving an email about horses changing sex. George gets frustrated when there's mistakes in the books--not just because mistakes can be embarrassing, though. He said there are inconsistencies in the books that are NOT mistakes. He believes in the "unreliable narrator" -- you can't always trust what people say because they might be remembering it wrong, or you get two different stories depending on who's doing the telling. He feels that mistakes such as eye color changes can distract from the planned inconsistencies, making them less effective.
So when measuring times in Westeros we need to know a relative scale for how long a year/month is. Whilst we have no exact timing for a month except they are measured in "moon turns" (how long is a moon turn? We don't know, likely the same as ours though ~30 days), we do know a year consists of twelve moon turns.
[What is the cycle of a year? Why do they count years when seasons are strange?]
Twelve moon tuns to a year, as on earth. Even on our earth, years have nothing to do with the seasons, or with the cycles of the moon. A year is a measure of a solar cycle, of how long it takes the earth to make one complete revolution around the sun. The same is true for the world of Westeros. Seasons do not come into it.
I have yet to properly double check, looking at other events in it, it does appear to be accurate, but this timeline for the whole series puts it around 6 months. A Dance with Dragons takes place solely in the year 300 AC so we already have an upper bound for the time they were placed in chains of a year.
Daenerys originally chains up Viserion and Rhaegal in "Daenerys II" of the book. The mentioned timeline puts this at the start of the year, the twentieth of the first month.
Viserion's claws scrabbled against the stones, and the huge chains rattled as he tried to make his way to her again. When he could not, he gave a roar, twisted his head back as far as he was able, and spat golden flame at the wall behind him. How soon till his fire burns hot enough to crack stone and melt iron?
Once, not long ago, he had ridden on her shoulder, his tail coiled round her arm. Once she had fed him morsels of charred meat from her own hand. He had been the first chained up. Daenerys had led him to the pit herself and shut him up inside with several oxen. Once he had gorged himself he grew drowsy. They had chained him whilst he slept.
Rhaegal had been harder. Perhaps he could hear his brother raging in the pit, despite the walls of brick and stone between them. In the end, they had to cover him with a net of heavy iron chain as he basked on her terrace, and he fought so fiercely that it had taken three days to carry him down the servants' steps, twisting and snapping. Six men had been burned in the struggle.
A Dance with Dragons, Daenerys II
Quentyn Martell later tries to tame and steal one of the dragons for himself, in the process they manage to escape; this happens in "The Dragontamer". However, the dragons are seen to be free in "The Queen's Hand" by Ser Barristan Selmy having escaped during the aftermath of the previous mentioned event. The timeline puts this event at the fifteenth day of the seventh month.
He took his last shuddering breath in the bleak black dawn, as cold rain hissed from a dark sky to turn the brick streets of the old city into rivers. The rain had drowned the worst of the fires, but wisps of smoke still rose from the smoldering ruin that had been the pyramid of Hazkar, and the great black pyramid of Yherizan where Rhaegal had made his lair hulked in the gloom like a fat woman bedecked with glowing orange jewels.
Ser Barristan went out onto the terrace. The rain had stopped, though a wall of slate-grey clouds hid the setting sun as it made its descent into Slaver's Bay. A few wisps of smoke still rose from the blackened stones of Hazdar, twisted like ribbons by the wind. Far off to the east, beyond the city walls, he saw pale wings moving above a distant line of hills. Viserion. Hunting, mayhaps, or flying just to fly. He wondered where Rhaegal was. Thus far the green dragon had shown himself to be more dangerous than the white.
A Dance with Dragons, The Queen's Hand
Taking these times together the difference is 5 months, 3 weeks, 4 days from our calendar. This would then be ~6 months when we take into account an error margin and the fact that Westerosi months aren't exactly the same as ours.