optimset() appears to be in base MATLAB, but there is an enhanced version in the Optimization toolbox because the help says "If you have an Optimization Toolbox™ license, you can also use optimset to create an expanded options structure containing additional options specifically designed for the functions provided in that toolbox."
I don't know how to determine in advance if your code uses the expanded options version or the base version. I don't think doing a dependency report would tell you that. If you want to do a dependency report that lists all functions used by your function you can click on the little down arrow on the title bar of the Current Folder window and do Reports/Dependency Report. It will tell you if the function is a toolbox function, but if you don't have that toolbox, it will just say "unknown" in a red box.