Yes, you can replace the CPU to an i7-6700.  But the machine hardware is still not eligible for Windows 11 support.As point out by other poster, search online for processes to bypass requirements for Windows 11 installation.  The 3040 was released in 2015, just a short time before Windows 10 came out.  So the machine does not have the support hardware requirements for Windows 11, release in 2021, and for certain, it won't met the requirements for Windows 12 which will be released next year.Windows 10 is still support for another 2 years, and your machine will be 10 years old.  You may need a new computer by then.
I cannot update my PC OptiPlex 3040 to Windows 11. The CPU, Intel(R) Core(TM) i5-6500, is not supported for Win 11. How to resolve the problem?
OptiPlex 3040 does not meet requirements for Win11