Note that there are more than two possibilities here. You could use "couldn't", "wasn't able to", or "hasn't been able to". The reason "hasn't been able to" is better than either of the other two is that she still can't visit them. The present perfect is generally the correct verb tense to use when you have a condition that extends from the past into the present, and "hasn't been able to" is present perfect, while both "couldn't" and "wasn't able to" are simple past.
In both the sentences:
She couldn't visit them for years, but …
She wasn't able to visit them for years, but …
the word but sets up the expectation that the first clause is no longer true. However, in the sentence
She hasn't been able to visit them for years, but …
this doesn't happen; because you used the present perfect, the listener knows that the first clause is still true, and so is not surprised when the second clause fails to contradict the first.
I believe that you could replace every were able to in your examples with could, but it might not mean what you think it means, and it could sound strange or misleading enough that some grammar books make it a rule that you must not use it. For example,
11.12.3 Specific achievement in the past
Could cannot normally be used when we are describing the successful completion of a specific action: was/were able to, managed to or succeeded in + -ing must be used instead.
In the end they were able to rescue the cat on the roof.
In the end they managed to rescue the cat on the roof.
In the end they succeeded in rescuing the cat on the roof.
--Longman English Grammar, L. G. Alexander
However, I think this is a little too simplified, and it could cause confusion, even for advanced learners. In my opinion, it is easier to think that
- could suggests the possibility to do the action, but they probably did not do it, while
- was/were able to suggests that they could do it, and they did it successfully.
And because of that, was/were able to is preferred when we are talking about the successful completion of a specific attempt. Though I believe that this might not be a hard-and-fast rule. The was/were able to always suggests that it's very likely that the attempt was successfully made. The managed to and succeeded in also suggests so, and the achievement is even more definite.
Let's consider the examples:
The fire spread through the building very quickly, but everyone could escape.
The fire spread through the building very quickly, but everyone was able to escape.
(Both versions suggest that they had a chance to escape, but only the second suggests that they really made it, safely.)
They didn't want to come with us at first, but finally we could persuade them.
They didn't want to come with us at first, but finally we were able to persuade them.
(Both versions suggest that we had a possibility to persuade them, but only the second suggests that we really persuaded them, successfully.)
Now the examples from COCA,
I told her to get in line. Did it make you feel better? It did. I finally could say something.
(This means that "I" finally had a chance to say something. Did "I" say something? Maybe, maybe not. Though it sounds likely that "I" did say something. It might not be so.)
Then, when it ended and I finally could get my family back, it came at a price, like suddenly being blind.
(What the text really states is that "I" finally had a chance to get "my" family back. Though it sounds likely that "I" did really get the family back. It might not be so.)
This should answer your question "Are these examples grammatically incorrect?".
Of course not. They are grammatically correct.
Best Answer
This is my understanding of what your example sentences mean:
Now, could we replace be able with could?
This scheme is impossible with could because it is a special form of verb: an auxiliary verb. It is a past-tense form of the verb can.
Auxiliary verbs are "defective". The verb can has no participle forms: you can't say "I had canned play tennis but then I broke my leg" or "I am canning to dance!". So we can't take have (or had) and add the past participle of can to it, since there's no such thing.
When you add have after could, it has an effect quite unlike that of the Present Perfect. The construction serves to express disbelief about a past event or action:
Your example 4 is easier to explain: we do not use had after could, so
..is ungrammatical.
What could we do with could? Only one thing:
What would be the meaning? In the past, there was a 2-year period during which I wasn't able to find my keys. Do I have the keys now? Who knows! How long ago did this 2-year period end? Who knows! So it's better to use be able to to express more "advanced" meanings.