As with .each we are able to get only 4000 and with get range maximum 1000.
Could you please share the full script, if possible.
Sounds you like you probably have a really inefficient loop/sort, you have to be doing a lot of things to exceed the call stack.
To avoid this error include firefieldchanged parameter in script and set it to False. This error is because of an unending loop exists in field change event.