The big problem... is that the expression has appeared in many forms down the years, such as four different ways from Sunday, eight ways from Tuesday, forty ways till Sunday, and a thousand ways for Sunday.
The key to its origin lies in this early slang collection, which was pointed out to me by Douglas Wilson:
This is an early American version:SQUINT-A-PIPES. A squinting man or woman; said to be born in the middle of the week, and looking both ways for Sunday; or born in a hackney coach, and looking out of both windows; fit for a cook, one eye in the pot, and the other up the chimney; looking nine ways at once.----Dictionary of the Vulgar Tongue, by Captain Francis Grose, 1785.
The brow projected exuberantly, though not heavily, over a pair of rascally little cross-firing twinkling eyes, that, as the country people said, looked at least nine ways from Sunday.----Cobus Yerks, a short story by James Kirke Paulding, in The Atlantic Souvenir for Christmas 1828.It would seem that Paulding employed an amalgamation of the first and last of Grose’s expressions to describe what is properly called a strabismus, in which the eyes appear to be looking in different directions...As well as the multitudinous versions, the sense has shifted yet again, to mean completely, thoroughly or by every imaginable method, as in this example from 1894: “if you want to collect any bills from them you will have to chase them seven ways from Sunday”. Another, from 2013, also has that sense: “They both insist that their staff are the best in the business, and have been checked five ways to Sunday before they get hired.”
More details at the always-interesting World Wide Words.