Hi at first at all you need the Stock rom and flash tool. Best way is over Moto-Lenovo Tool. Than need Seach how back-up the DB's from sec-partition, for Write later all Info back to the Phone like in Factory. Like : Barcode, WiFi Mac address, Bluetooth mac address, Imei1 and Imei2 also all other details. Search for recovery Imei and wifi mac address. i Found here on xda all infos allready.
When you have all, than you need use the flash tool from Moto-Lenovo to format all the Phone, but make Sure you have the DB's for restore all info. Than you flash the Phone again with the Stock-Rom.
After you flash the Rom, you need Write the S/N, IMEI, Wifi and Bluetooth Mac address, also the Barcode. than the Phone is like new.