If you upgrade to Windows 10 first, you can then re-install and Windows 10 will automatically activate once you connect to the internet.
There is no installation code required for windows 10 installation having the widows 8 in your PC or Laptop by just reinstall it and the windows 10 will automatically activate.
It's likely though that this does not work if you change motherboard. All Windows 10 does is store a copy of the license on their servers and link it to your system. You'd still need to use phone activation to verify your license if the system it's attached to becomes too different. I don't know how this works if the license is actually on the motherboard itself (through UEFI support). Maybe these won't work with phone activation, but I haven't had the opportunity to experiment in UEFI territory yet.
If you change motherboard you can re install Windows 10 from a Version 1511 (November 2015) ISO or later. Doing this will accept your Windows 7 Or Windows 8 CD Key and re-activate when you connect to the internet. That might not always work (when changing motherboard) however currently it does as Microsoft are still activating new Windows 10 installs which used a Windows 7 or 8 key, despite the free upgrade offer having ended. The licence is tied to the hardware for the free upgrades however, so in the future if you change the motherboard you will have to purchase a new Windows 10 licence for that motherboard, however you then have a unique key, so if you change motherboard again after that you can call Microsoft up and activate with your purchased key.