Nobody can tell you that with any certainty. I think expecting a current totally-non-upgradeable Mac to last you for 10 years is optimistic... not impossible, but optimistic. For the iMacs you're looking at I would say the M4 because - as I said - the M3 is at least 1 year, maybe more (depending on when the current M4 model is discontinued), closer to Apple's "vintage" and "obsolete" points.
Find out more about your options for getting a service and parts for Apple devices that are past their warranty period.
support.apple.com
Although that's just talking about hardware, I suspect the reality is that as long as Apple
might have to repair a model there will be a
supported version of MacOS (receiving essential security updates & not locked out of any
pre-existing Apple services) for it.
That's not the same as being able to run the
latest version of MacOS - that's harder to predict since Apple has no published policy but tends to extend for 5-6 years after release. Honestly, we haven't seen Apple's behaviour w.r.t. Apple Silicon Mac yet. It could go either way - it should be
easier to offer long-term support for Apple Silicon - with so much of the functionality on Apple's own system-on-a-chip & the same few SoCs used across the whole Mac range there are far fewer processor variants, 3rd-party GPUs & other 3rd party components/drivers for Apple to keep check on c.f. the Intel Macs. OTOH, the tighter control Apple has may encourage them to double-down on "planned obsolescence"
There's all sorts of imponderable questions - as long as it stays working it
should keep doing whatever it does today, but these days we can't be sure whether (say) Microsoft will try and force you onto a new version of Office (either via subscriptions/updates or by changing the file format...), when you won't be able to run a "safe" web browser, or when Mail will stop connecting to your work email because security (this happened to me a few years ago with an old MBA - don't bother suggesting work arounds, folks - when work IT say "no" that's the end of it).
Given you're starting at 16GB RAM/512GB SSD I
don't think that upselling you to an iMac with more RAM and storage will have a big impact on longevity (I wouldn't get 8GB or 256GB).
Now, please don't rely too much on the following, but going for a M4 Mini + separate display
might be better for longevity because:
1. If either the display or the computer fails, you can replace it separately
2. The M4 Mini at least has socketed SSD modules (probably the most likely bit to die) so, at a minimum, an Apple repair place should be able to replace them (& there's still the off-chance that DIY repairs/upgrades might become feasible).
...but that does raise the dilemma about which display to get (you can search these forums for
s lot of argument about that).