(instead of a comment) I would go for the minimization of information criteria either AIC or BIC, or any other just choose the parameter k other than 2 in AIC() function:
require(urca)
## An example from example(ur.za)
data(nporg)
gnp <- na.omit(nporg[, "gnp.r"])
za.gnp <- ur.za(gnp, model="both", lag=2)
AIC(eval(attributes(za.gnp)$testreg))
[1] 485.0148
BIC(eval(attributes(za.gnp)$testreg))
[1] 501.6351
For the efficient implementation you may consult on the stack-overflow, I think. A rough way to go is to run the for cycle, but it may be too slow.